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.

Recognizing a Header Row when Sorting

by Allen Wyatt
(last updated June 14, 2014)

23

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.

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

Highlighting Pattern Violations

A common part of working with text strings in a worksheet is normalizing those strings so that they follow whatever rules ...

Discover More

Marking Multiple Documents

After using Word for a while, it is easy to accumulate quite a few documents. At some point you may want to make a change to ...

Discover More

Exporting Black and White Charts

Excel's charts are normally created in color, but you can print them in black and white. You may be looking for a way to ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (menu)

Determining Sorting Criteria

If you need to know how a range of data is sorted, the task is not as easy as you might at first think. This tip examines why ...

Discover More

Sorting Data Containing Merged Cells

When formatting the layout of your worksheet, Excel allows you to easily merge adjacent cells together. This can cause havoc ...

Discover More

Sorting Huge Lists

Got a huge amount of data you need to sort in a worksheet, but Excel doesn't seem to be sorting it correctly? Here's some ...

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}] 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 nine minus 3?

2017-04-24 18:41:08

Dave

I tend to get the opposite problem - Excel incorrectly assuming the first row of my selection is a header row and failing to sort it with the rest of the data. What's the fix for this?


2016-12-09 07:52:35

Matt

Alternative option: use google. Google recognizes a multi-row header and doesn't require you to jump through any hoops. It just works.


2016-10-17 14:15:25

Jonathan Sanders

Thank you Jay! That fixed a very common and frustrating problem for me.


2016-08-10 05:16:53

Bruce L

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.


2016-08-09 17:08:58

Rach

Jay had the best answer and was the easiest to follow. The description above is just confusing at best...


2016-03-20 13:23:54

Cheryl

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.


2015-11-10 17:38:27

Jerry

"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"


2015-08-21 11:39:59

Eduardo

Insterting a blank line below headers and
Ctrl+Shift+8 supplies most of my sorting needs. Thanks!


2015-08-06 12:50:00

Jessie

Can we make excel always have the box "my data has headers" checked off? I have to always check that.


2015-05-10 23:28:58

Joe Hardy

To echo Diane, thanks Jay!


2015-04-18 11:58:31

Diane

JAY,

Thanks for the tip! That saved me a lot of time. Your instructions were simple and exact.


2015-01-14 19:44:22

LR

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.


2015-01-04 10:24:02

Bruce L

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.


2015-01-02 17:16:06

Jay

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.


2014-12-02 05:32:38

Bruce L

Melly I think everyone knows that - this article is about getting Excel to automatically recognise column headers when sorting without using the dialog.


2014-12-01 19:34:31

Melly

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.


2014-10-27 01:19:16

Dan

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.


2014-09-24 05:22:39

BruceL

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.


2014-09-23 11:42:10

Katie

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.


2014-08-29 12:00:14

Paula

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?


2014-08-29 10:51:40

newp

gffsdg, you just got served!!


2014-07-09 16:52:35

awyatt

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.

-Allen


2014-07-09 16:43:53

gffsdg

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?


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon 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.