Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Recognizing a Header Row when Sorting.

Recognizing a Header Row when Sorting

Written by Allen Wyatt (last updated October 31, 2020)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


1

Let's assume that you are working with data in a worksheet and that data is not designated as a structured table. (In my experience, most data in worksheets isn't designated as a structured table—it's just data in the worksheet.) There are two ways you can sort your worksheet information: using the Sort Ascending and Sort Descending tools on the Data tab of the ribbon or by using the Sort dialog box. (The Sort dialog box is displayed by clicking the Sort tool on the Data tab of the ribbon.)

Using the Sort Ascending and Sort Descending tools allows you to do your sorting quicker, but Excel makes a few assumptions in the process. If you don't understand these assumptions, you may not end up with the sort results you expect.

First, Excel assumes that you want to sort only by the column of whatever cell you have selected. If you want to perform secondary and tertiary sorts on more than one column (or row), you need to use the Sort dialog box.

The second assumption affects exactly what Excel sorts. If you have a single cell selected in a larger range of data, Excel extends the selection to select that larger range, much like pressing Ctrl+Shift+8. In extending the selection, the resulting range is bounded by one or more blank columns and rows. Excel then examines the first row in the selected range to determine if it contains header information or not.

This is where sorting with the Sort Ascending and Sort Descending tools can become tricky—your header (assuming you have one) must meet some rather strict guidelines in order for Excel to recognize it as a header. For instance, if there are any blank cells in the header row, Excel may think it isn't a header. Likewise, if the header row is formatted the same as the other rows in the data range, then Excel may not recognize it. As well, if your data table consists entirely of text and your header row contains nothing but text, Excel will—virtually all the time—fail to recognize the header row. (The row looks just like another data row to Excel.)

Only after selecting the range and determining if there is a header row will Excel do the actual sorting. How pleased you are with the results depends on whether Excel got both the range selection and the header row determination right. For instance, if Excel doesn't think you have a header row, and you do, then your header is sorted into the body of the data; this is generally a bad thing.

To make sure that your data range is recognized correctly, use the Ctrl+Shift+8 shortcut to see what Excel selects; this is what will be sorted. If it doesn't match your expectations, then you need to either modify the character of the data in your table, or you need to select the data range before using the Sort dialog box.

To make sure that your heading is recognized correctly, use the Ctrl+Shift+8 shortcut to select the data range, then look at the first row. If your header has blank cells among those selected in the first row, or the first row is formatted just like the second row, or you have more than one header row selected, then Excel assumes you have no header row at all. To correct this, make changes in your header row to make sure it is recognized properly by Excel.

Finally, all bets could be off if your data table uses multi-row headers. Excel has a hard time recognizing them. You compound the problem when you expect it to include blank rows in that header; it just can't do it automatically. You can, however, simply select all the rows you want to sort before doing the sort. In other words, be specific in what you want Excel to sort; don't let Excel make the assumptions for you.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9423) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Recognizing a Header Row when Sorting.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Limiting Scroll Area

If you need to limit the cells that are accessible by the user of a worksheet, VBA can come to the rescue. This doesn't ...

Discover More

Ensuring Standard Units During Data Entry

Need to make sure that information entered in a worksheet is always in a given unit of measurement? It's not as easy of a ...

Discover More

Printing an Outline

Outlining is a great way to develop the content of your document. If you need to, you can even print the outline and only ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

Sorting Letters and Numbers

Sorting information in a worksheet can be confusing when Excel applies sorting rules of which you are unaware. This is ...

Discover More

Can't Sort Imported Data

Import information from an external database, and you'll no doubt want to use Excel's simple tools to manipulate that ...

Discover More

Sorting Dates by Month

Sorting by dates is easy, and you end up with a list that is in chronological order. However, things become a bit more ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is two more than 5?

2021-01-30 15:27:22

John Mann

I had never noticed these problems before, for the simple reasons that I always format my heading rows in such a way as to make them visibly obviouls as headers - bold, larger font, vertically centred, maybe horzontally centred, usually a somewhat higher row height, etc. (Any or all of those, and sometimes other features). I also often have a blank row (likely of reduced height) between my headers and the data. I just can't imagine creating a table of data without headings and making the headings distinctive visually from the data.

Similar comments would apply to any "row headings" in the left column(s)


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.