Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Office 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

by Allen Wyatt
(last updated January 10, 2020)


There are two ways you can sort information in Excel: using the Sort Ascending and Sort Descending tools on the toolbar or by using the Sort dialog box. Using the toolbar tools allows you to do the sort more quickly, but Excel makes a few assumptions in the process.

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, Excel extends the selection to select a range (much like pressing Ctrl+Shift+8) bounded by one or more blank columns and rows. It then examines the first row in the selected range to determine if it contains header information or not.

This is where sorting with the toolbar 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 Office 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. ...


Automatically Adjusting Height for Text Boxes

Text boxes are often used to enhance the layout of documents. You may want a text box that adjusts its height ...

Discover More

Superscripts in Find and Replace

The find and replace used in Excel is less powerful than its counterpart in Word, so it is not able to do some of the ...

Discover More

Setting Defaults in the Cross-reference Dialog Box

Some types of documents rely on cross-references quite a bit. Setting up the Cross-reference dialog box the first time in ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Sorting an Entire List

Need to sort all the data in a table? Here's the fastest and easiest way to do it.

Discover More

Understanding Ascending and Descending Sorts

When you sort information, Excel follows a set pattern of how your data is organized. This tip illuminates the burning ...

Discover More

Importing Custom Lists

Custom lists are handy ways to enter recurring data in a worksheet. Here's how you can import your own custom lists from ...

Discover More

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

View most recent newsletter.


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}] 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 2 - 2?

2018-12-19 02:57:44


Another issue is using the macro recorder when sorting.
First, the recorder always sets the parameter Header:=xlGuess. It is preferable to change this to xlYes if your sort shall include the header (or xlNo if not).
Second, if you have headers in your table, the VBA result uses the cell address for key columns, e.g. Key1:=Range("A2"). In order to increase readibility, it is possible and advisable to change this to the header title, e.g. Key1:="Region".

2017-07-06 14:32:48

Sara-Sue Schreiber

thank you! This helped immediately! Excel "help" didn't work for me at all.

2017-03-18 13:37:30

Christopher Huergo

For a long time, I couldn't figure out why "My data has headers" was constantly deselected in only one of my workbooks. I didn't *think* I had any blank cells in the header row, but I did: in MERGED cells. When merging, you know how it says it only keeps values in the upper left and discards other values? If you merge, it makes one header cell blank, which causes "My data has headers" to constantly be deselected. I un-merged them and entered values into each, now "My data has headers" is always selected. If you want the opposite, then merge two header cells, or insert a blank column into the worksheet and hide it. I haven't tried the latter, but I think it would have the same effect.

2016-08-11 10:46:53

Lisa Lynch again

I was devastated to find that the fix I posted yesterday didn't stay fixed. I did find a problem, though: When I sort only a part of the spreadsheet in the Sort dialog without using headers, the fix doesn't work again. Obviously, when I bypass the headers in sorting, I must go back to the Sort dialog and check "My data has headers" again.

2016-08-10 15:17:02

Lisa Lynch

You've solved a problem that has frustrated me every day for months. I create several new spreadsheets every day and format them all the same with a macro. I added one step to my macro: after all the columns are formatted in their several ways, go back and format the first row as text. Problem solved forever.

Thank you so much for this information. I've subscribed to your newsletter and look forward to learning something new every week.

2016-07-18 14:40:10


I would like to change the default for sort so it does NOT have the headers box checked. Is there a way to do this?
thanks, Judy

2016-07-17 14:36:28


My data has headers always gets selected, but my area that is to be sorted does not have header row, or I do not recognize them. Sometimes when I sort the first row is not included in the sort area and lands on top, therefore the complete area is not sorted. Is there a way to turn this option off so I won't have to keep deselecting this box and re-sort.


2015-07-11 17:16:01

Marc Kupper

Here's a fix that may work for some people. I use Excel 2010 but suspect this will work with other versions.

1) Press Alt-D-S or select the Data tab and then the Sort icon on the menu/ribbon bar to bring up the Sort dialog box. You see that the header is not recognized.
2) Take a look at what column Excel wants to sort by. Let's say it wants to sort by column G.
3) Cancel out of the sort dialog.
4) Click on any cell in column G.
5) Do Alt-D-S again. For me, this time Excel recognized the header.

Once I did the sort Excel continues to recognize the header. I did an immediate undo of the sort and Excel continued to recognize the header. Apparently Excel gets into a mode where it won't recognize the header. Your header row and data are fine but for whatever reason Excel is refusing to recognize the header even if you select "My data has headers."

The fix that worked for me was noticing that even though I was on a cell in some random column that Excel wanted to sort by a column that was not the one that was currently selected. I canceled the sort, selected a cell in the column that Excel wanted to sort by, and Excel's header detection logic fixed itself.

2015-01-21 11:49:56


I have Excel 2010.
When I press ctrl-shift-8, nothing happens.
Is there a setting I need to change?

The top row is formatted as text. The others are formatted as numbers or dates.

2014-10-09 15:55:19

Barton Lewis

Nothing I do keeps the header row as a header row. I admit I don't understand the directive to use Ctrl Shift 8, since that just selects the entire document. Is that what was intended?

I've made sure the header is bold-faced, that there are no empty cells, etc. The help feature in Outlook 2013 tells me to find Table Tools, Design, Table Style Options to get to Header Row. I can't find Table Tools on any tab.

2014-07-02 08:54:54


@mdeva: ... what? Recording macros works, but the recording is pretty literal. Don't blame Microsoft for your own lack of understanding.

@Misange: I'm not sure I'd call it "missing obvious tools". Tables by definition have headers, so sorting without headers doesn't make sense. Similarly, sorting left-to-right presumes a data structure where the "headers" are in the right column, which just isn't how tables are designed. Sure, there might be times where you want to rearrange the columns, but (a) you are not stopped from doing so (just from using the sort tools to do so) and (b) the reasoning would be aesthetic, not data-driven. Try doing any of those manipulations in a database application!

2014-07-01 09:55:15


I came to the same conclusion. Silly...
Tables are powerful and very useful but obvious tools are missing.

2014-07-01 07:26:17


Excel is deteriorating with every release. E.g. try recording a macro - then running it. Doesn't work anymore. M-soft no longer tests their releases. Just throws it out there - then reacts to complaints.

2014-06-30 10:11:04


@Misange: You can't sort a structured table in that way. The easiest thing would probably be to unstructure the table (Right click > Table > Convert to Range), do the sorting, then make it a table again (Ctrl+T)

2014-06-30 01:55:52


Hi Allen,
I could not find how to sort an excel table (2003 lists) alphabetically by the header of the table. The option "sort from left to right" is not available in tables and you cannot uncheck the option "my data have headers".
Any idea ?

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

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.