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

Sorting Letters and Numbers

Written by Allen Wyatt (last updated June 15, 2019)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


3

Let's say that you have a worksheet in which a particular column, for instance column C, 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 (this formula assumes the data you are sorting begins in cell C1):

=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 (9600) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel 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

Endnotes in a Separate Document

When you add endnotes to a document they are normally positioned (as one would expect) at the end of the document. You ...

Discover More

Avoiding the "Check Remainder" Dialog Box

Need to check grammar using a macro? Word includes a couple of different ways to perform the check, and what you see ...

Discover More

Seeing the Height of a Row

Want to see the exact height of a row? This tip provides a quick and precise way that you can see that height.

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (ribbon)

Preventing Jumbled Sorts

Click the Sort tool in Excel, and you may be surprised that the data in your worksheet is jumbled. In order to sort ...

Discover More

Sorting by the Last Digits in Variable Length Data

Excel is great at sorting information in a worksheet. Sometimes it can be a bit confusing as to how to set up the sort ...

Discover More

Performing Complex Sorts

One way you can easily work with data in a worksheet is to sort it into whatever order you find most helpful. Excel ...

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 0?

2019-06-16 09:58:58

Harold Druss

How about a simple macro? No padding.
Data in Col A, Col B no data
=========================================
Sub SortWithFirstLetter()
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
FirstLetter = Left(Cells(1, 1), 1)
For i = 1 To LastRow
Cells(i, 2) = Mid(Cells(i, 1), 2)
Next
Range("B1:B" & LastRow).Sort Key1:=Range("B1"), Order1:=xlAscending, Header:=xlNo
For i = 1 To LastRow
Cells(i, 1) = FirstLetter & Cells(i, 2)
Next
Columns("B:B").Select
Selection.ClearContents
End Sub


2019-06-16 08:33:56

Stephen Argent

Hi Allen,
There's another way around that particular problem:
Format the cells using the number format "F"0
That way you can enter the the numbers as numbers and the formatting will add the letter "F" in front, but Excel will still recognise them as numbers.

Best,
Stephen


2019-06-15 13:25:44

Willy Vanhaelen

This is a shorter formula:

=LEFT(C1,1)&RIGHT(1000+MID(C1,2,3),3)


This Site

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