Recognizing a Header Row when Sorting
Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Recognizing a Header Row when Sorting.
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 it 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 (2586) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Recognizing a Header Row when Sorting.
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!
Leave your own comment:
Comments for this tip:
Bruce L 10 Aug 2016, 05:16
Rach: If Jay's solution fixed your problem that's great, but it also means you had a different problem to the one discussed above.
Rach 09 Aug 2016, 17:08
Jay had the best answer and was the easiest to follow. The description above is just confusing at best...
Cheryl 20 Mar 2016, 13:23
I've had this issue and searched in vain for an answer. But I have a possible solution. If you're sure your headings fit the specifications required by Excel - per the prior explanations - and your data is still sorting the headers into the rest of the data - it could be that Excel believes there's something in an adjacent column. In my case I've deleted the column to the right of my data, inserted a new blank column and that still didn't solve the issue. BUT, copying the database - and only the actual data set - to a new sheet worked. Excel sensed the header row and now sorts correctly without my having to use the Data/Sort menu.
Jerry 10 Nov 2015, 17:38
"To correct this, make changes in your header row to make sure it is recognized properly by Excel."
This is a fairly long winded explanation of why your header row sorts in with the rest of your data. The above answer is extremely inarticulate and makes this a relatively frustrating article...."let me explain in detail why your problem exists. The answer is: fix it, stupid"
Eduardo 21 Aug 2015, 11:39
Insterting a blank line below headers and
Ctrl+Shift+8 supplies most of my sorting needs. Thanks!
Jessie 06 Aug 2015, 12:50
Can we make excel always have the box "my data has headers" checked off? I have to always check that.
Joe Hardy 10 May 2015, 23:28
To echo Diane, thanks Jay!
Diane 18 Apr 2015, 11:58
Thanks for the tip! That saved me a lot of time. Your instructions were simple and exact.
LR 14 Jan 2015, 19:44
I use 'Excel for Mac 2011'.
How do I sort a column AND still retain the #1 heading 'row' intact at the top and not be included in the sort?
NB: I need to globally select the WHOLE column - as I have hundreds and hundreds of rows and I don't want to have to selectively select the data in the column ie by leaving out the heading).
I am unable to get the above solutions working in Excel for Mac.
Solution will be greatly appreciated.
Bruce L 04 Jan 2015, 10:24
I think this page is destined to collect comments from well-meaning people trying to help but who either haven't really read the article or don't understand the reasoning behind it.
Jay 02 Jan 2015, 17:16
For Excel 2010:
1. Click the "triangle" to the left of Column Label "A" and right above Row Label "1" to select all of you data (or "CTRL + A" to select all)
2. Click the "DATA" tab
3. Click the "SORT" button
4. Click to check the checkbox on the top right-hand corner (right below the close/X button) that says "My data has headers".
5. Then select the column(s) you would like to sort by and click "OK".
Provided you have your "header/label" row at the very top of all your data, excel will almost always sort your data range below the labels and keep your label/header row at the top.
Bruce L 02 Dec 2014, 05:32
Melly I think everyone knows that - this article is about getting Excel to automatically recognise column headers when sorting without using the dialog.
Melly 01 Dec 2014, 19:34
Click on the Data tab, under the Sort & Filter Group click on Sort. The Sort dialog box appears. In the top right hand corner of the box - check "My data has headers" box. The range to be sorted is highlighted. Click on OK to confirm and your data will sort with the headers intact.
Dan 27 Oct 2014, 01:19
I assume the "no real solution" comment was something like "how can you force Excel to recognize that my header exists?" *I* do that by inserting a blank row between the bottom of my header and the rows that contain the data I'm sorting. Excel will always hit the blank and stop, unless you selected through the blank into the header.
BruceL 24 Sep 2014, 05:22
You didn't find an answer to your exact problem so you chose to criticise the person who went to the effort of preparing fairly comprehensive general help on the subject? You need to be a bit less ungrateful.
Katie 23 Sep 2014, 11:42
You really need to organize your information better. This took way to long to read through, only to find out you offer no real solution.
Paula 29 Aug 2014, 12:00
I am sorting one column by alphabetizing names. That part is done. Now I'd like to total the amounts in an adjacent column for each name. How do I do that?
newp 29 Aug 2014, 10:51
gffsdg, you just got served!!
awyatt 09 Jul 2014, 16:52
It displays after 45 seconds. It is not selling anything, but offering you a chance to subscribe to the free weekly ExcelTips newsletter.
If you don't want to, fine. Just close the window and, if you have cookies enabled on your system, you won't see the subscription offer again for six months.
Of course, all this is explained in that window, in a bit more detail.
gffsdg 09 Jul 2014, 16:43
What's with the annoying pop-up message that appears after a few seconds? I am extra unlikely to buy any product offered in a pop-up message?