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

by Allen Wyatt
(last updated January 16, 2016)

4

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

Changing a Heading to Body Text

When working on an outline of your document, you may want to demote a heading so that it is treated just like your body text. ...

Discover More

Extracting Street Numbers from an Address

Want to know how to move pieces of information contained in one cell into individual cells? This option exists in using ...

Discover More

Swapping Two Numbers

When programming macros, variables are used extensively. At some point you might want to exchange the values held by two ...

Discover More

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!

More ExcelTips (menu)

Sorting a Range of Cells

When you sort data in a worksheet, you don't need to sort everything at once. You can sort just a portion of your data by ...

Discover More

Storing Sorting Criteria

Need to do the same sorting operation over and over again? Excel doesn't provide a way to save your sorting criteria, but ...

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
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 four less than 9?

2016-01-17 13:09:19

Nancy

Harris Dimoliatis There are two ways to approach this. One would be to be add a column and use the formula
=IF(LEN(A3)=15,RIGHT(A3,3),RIGHT(A3,2))
(assuming your data is in Column A) Sort all columns by the new column choosing sort anything that looks like a number.

Another way would be to copy the column and parse using text to columns and the deliminter "=". Sort all data by the number column. This will take care of numbers of any length. The first one will need nested if you have numbers less than 2 digits long or more than 3


2016-01-16 06:34:26

Michael (Micky) Avidan

@yaser abu odeh,
Assuming your list resides in column "A" starting in cell A1:
1) In cell B1 type: =MID(A1,9,2) and copy down as long as your list.
2) Sort BOTH columns in ascending order according column "B".
*** Now you can delete the helper column "B".
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2016)
ISRAEL


2016-01-16 00:16:58

yaser abu odeh

how can i sort the following according to the two letters inside:-
61384589TB0439
61388315BG0121
61238348FX0139
61238348RI0139
61388627BS0139
61388627FG0241
61388634BG0121
61874018ET0186
61654324BS0142
61884324ET0141
61888004FX0146
6138321CBG0121
61388003SS0326


2016-01-14 13:54:10

Harris Dimoliatis

I have exactly this problem, but i didn't get the tip.
I have to sort this and i need a "O" after the "="
category_id=168
category_id=169
category_id=17
category_id=171
category_id=173
category_id=174
category_id=175
category_id=176
category_id=177
category_id=178
category_id=18
category_id=182
category_id=183
category_id=184


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.