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: Sorting Letters and Numbers.

Sorting Letters and Numbers

Written by Allen Wyatt (last updated November 9, 2024)
This tip applies to Excel 97, 2000, 2002, and 2003


Let's say that you have a worksheet in which a particular column contains entries such as F1, F2, F3, etc., all the way up to F149. If you need to sort the data in the worksheet based on the contents of this column, the results may disappoint you. Because the first character in each cell is a letter, Excel sorts the column as text.

The upshot is that the cells are sorted in the order F1, F10, F100, F101, F102, etc. In this arrangement, F2 doesn't show up until the sixty-second entry in the sorted list. The reason this happens is because the cells are treated as text. As text, all the cells starting with F1 (there are 61 of them) come before the cells starting with F2.

The only way around this situation is to make sure that the numbers in the cells are front-padded with zeros. In other words, you shouldn't use F1, but F001. You can use the following formula to convert the old format numbers to the new format:

=LEFT(C1,1) & RIGHT("000" & RIGHT(C1,LEN(C1)-1),3)

Now, when you sort by the newly formatted entries, you get the desired results: F001, F002, F003, etc.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2609) 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: Sorting Letters and Numbers.

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

Determining the Upper Bounds of an Array

When working with variables in a macro, you may need to know the upper boundary dimension for an array. This can be ...

Discover More

Protecting a Graphic

Need to make sure that someone cannot delete a graphic in a worksheet? The ability to protect the graphic depends on ...

Discover More

Converting Numbers to Strings

VBA is great at working with both strings and numbers. At some point, you may have a number you need to convert to a ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development 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 ...

Discover More

Sorting Decimal Values

Government and industrial organizations often use a numbering system that relies upon a number both before and after a ...

Discover More

Sorting by Colors

Need to sort your data based on the color of the cell? Excel doesn't include this capability, but you can still do the ...

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 two more than 7?

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.