Loading
ExcelRibbon.Tips.Net ExcelTips (Ribbon Interface)

Recognizing a Header Row when Sorting

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

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 (9423) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Recognizing a Header Row when Sorting.

Related Tips:

Got the Time? Understanding the ins and outs of working with times and dates can be confusing. Remove the confusion--ExcelTips: Times and Dates is an invaluable resource for learning how best to work with times and dates. Check out ExcelTips: Times and Dates today!

 

Comments for this tip:

Bryan    02 Jul 2014, 08: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!
Misange    01 Jul 2014, 09:55
@Brian
I came to the same conclusion. Silly...
Tables are powerful and very useful but obvious tools are missing.
mdeva    01 Jul 2014, 07:26
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.
Bryan    30 Jun 2014, 10:11
@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)
Misange    30 Jun 2014, 01:55
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 ?

Leave your own comment:

*Name:
Email:
  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*Text:
*What is 3+4? (To prevent automated submissions and spam.)
 
          Commenting Terms
 
 

Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us

 

Advertise with Us

Our Privacy Policy

Our Sites

Tips.Net

Beauty and Style

Cars

Cleaning

Cooking

DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2013)

Gardening

Health

Home Improvement

Money and Finances

Organizing

Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2013)

Our Products

Premium Newsletters

Helpful E-books

Newsletter Archives

 

Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2014 Sharon Parq Associates, Inc.