Sorting by Five Columns

Written by Allen Wyatt (last updated September 17, 2022)
This tip applies to Excel 97, 2000, 2002, and 2003


Excel includes a sorting feature that allows you to easily sort a data list by up to three columns. If you have a large or complex data list, you may want to sort by more than three columns, however. There are several ways you can accomplish this.

Assuming you have five columns you want sorted by, the first method is to just do two passes at sorting. If you want to sort the data in the order of columns A, B, C, D, and E, you would perform the first sort using columns C, D, and E. Once these are in order, sort by columns A and B. The result is that your entire data list is in order.

Closely related to this is the fact that you can use the sort tools on the toolbar to sort your five columns. First, choose a cell in column E, then click on either the Sort Ascending or Sort Descending tool. Repeat this process by selecting a cell in each of the other columns (D, C, B, and A), in turn, and clicking on the appropriate tool. At the end of this iterative process (which takes only five quick clicks of the sorting tools), your entire list is in the order you desire.

There is an important things to keep in mind when sorting as described here: The character of your list data can affect the quality of the sort performed. If your data contains empty cells, error values, or numbers formatted as text, then Excel may not sort the data in the method you expect. The solution is to "normalize" your data—for instance, making sure that numbers are really numbers and not numbers formatted as text—and then do the sort again.

Another solution is to create a "sorting column" for your data. This approach works great if your data is all text, or if you can easily convert it into a text-based format for the sorting. Under this scenario, you would combine the contents of columns A through E into column F, and then sort by a single column: F. You could use this type of formula in column F:

=A1 & B1 & C1 & D1 & E1

If one of the columns contains a date, you will need to convert the date to a consistent text format, as done with this formula:

=A1 & B1 & C1 & TEXT(D1,"yyyymmdd") & E1

If one of the columns contains numeric values, you can normalize them by using a similar TEXT function construct that pads the value with leading zeroes:

=A1 & TEXT(B1,"000000") & C1 & D1 & E1

If you do quite a bit of sorting, and you don't want to use Excel's built-in sorting routines, then you should investigate third-party sorting functions. Sorting algorithms are a fascinating branch of mathematics, and some very popular algorithms (such as shell sort, exchange sort, bubble sort, etc.) can be implemented through Excel functions. How those functions would be used on your system depends on the way they were implemented by their developer.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2255) applies to Microsoft Excel 97, 2000, 2002, and 2003.

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

Jumping to the Ends of Table Rows

Need to jump from one end of a table row to another? Word provides a couple of handy shortcuts that can make this type of ...

Discover More

Quickly Copying Styles

You can easily use regular editing techniques to copy styles from one document to another. Here's how to make quick work ...

Discover More

Printing a List of Custom Styles

You can add any number of styles to your document in order to define how you want your text to appear. If you later want ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (menu)

Too Many Formats when Sorting

Sorting is one of the basic operations done in a worksheet. If your sorting won't work and you instead get an error ...

Discover More

Creating a Sort Order

Excel is very flexible in how it can sort your data. You can even create your own custom sort order that is helpful when ...

Discover More

Automatically Sorting as You Enter Information

When entering information into a worksheet, you may want it to always be in a correctly sorted order. Excel allows you to ...

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 1 + 1?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


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.