How to sort numbers with text/letter prefix or suffix in Excel?
For example you have a series of numbers containing letter prefix or suffix, how could you sort them as normal numbers in Excel? This article collects several workarounds to get it done.
- Sort numbers with text/letter prefix or suffix by user defined function
- Sort numbers with text/letter prefix or suffix by extracting numbers
- Sort numbers with text/letter prefix or suffix by splitting text and numbers
- Sort numbers with text/letter prefix or suffix by removing letters
Sort numbers with text/letter prefix or suffix by user defined function
This method will introduce a user defined function (VBA) to extract numbers only from the numbers with prefix or suffix, and then you can sort easily.
1. Press Alt + F11 keys simultaneously to open the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and then paste below VBA code into the new opening Module window.
User Defined Function: Extract numbers only from text strings
Function num(rng As Range) As String
Dim n As Integer
For n = 1 To Len(rng)
If Mid(rng, n, 1) Like "[0-9]" Then
num = num & Mid(rng, n, 1)
End If
Next n
End Function
3. Save the code and close the Microsoft Visual Basic for Applications window.
4. Select a blank cell beside original numbers with prefix or suffix, says Cell B2, type the formula =num(A2) (A2 is the number with prefix or suffix) into it, and then drag this cell’s AutoFill Handle to the range as you need.
5. Due to extracted numbers stored as text, we need to convert them to numbers. Copy all extracted numbers, right click copied range and select Paste Values from the right clicking menu. See screenshot:
Note: In Excel 2007, you can copy the extracted numbers stored as text, and then click Home > Paste > Paste Values.
6. Keep selecting these numbers, and then click button beside selected numbers, and select the Convert to Number from the drop down list. See screenshot:
7. Keep the new numbers selected, and click Data > Sort Smallest to Largest or Sort Largest to Smallest; and then check the Expand the selection option in the popping up Sort Warning dialog box, and click the Sort button. See screenshots:


8. Now the numbers with letter prefix or suffix have been sorted as normal numbers sorting (See below screenshot). Please delete the extracted numbers if necessary.
Sort numbers with text/letter prefix or suffix by extracting numbers
Actually, Kutools for Excel also provides similar EXTRACTNUMBERS function to extract numbers from text strings. Therefore, we can sort numbers with letter prefix or suffix by extracting numbers firstly.
Kutools for Excel - Packed with over 300 essential tools for Excel. Enjoy a full-featured 30-day FREE trial with no credit card required! Download now!
1. Select a blank cell beside the numbers with letter prefix or suffix, says Cell B2, type the formula =EXTRACTNUMBERS(A2,TRUE) (A2 is the cell of number with letter prefix or suffix) into it, and then drag this cell’s AutoFill Handle to the range as you need. See screenshot:
2. Keep extracted numbers selected, click Data > Sort Smallest to Largest or Sort Largest to Smallest; check the Expand the selection option in the popping up Sort Warning dialog box, and then click the Sort button. See below screenshots:


3. Now numbers with letter prefix or suffix have been sorted as normal numbers sorting. And you can delete all extracted numbers as you need.
Sort numbers with text/letter prefix or suffix by splitting text and numbers
Kutools for Excel also supports to split text and numbers from cells by its Split Cells utility. Therefore, we can split the text and numbers and place them into different columns for easily sorting. Please do as follows:
Kutools for Excel - Packed with over 300 essential tools for Excel. Enjoy a full-featured 30-day FREE trial with no credit card required! Download now!
1. Select the numbers with letter prefix or suffix, and click Kutools > Text > Split Cells. See below screenshot:
2. In the opening Split Cells dialog box, please check the Split to Columns option in the Type section, check the Text and number in the Split by section, and click the Ok button. See above screenshot:
3. Now the second Split Cells dialog box comes out. Please select the cell beside original numbers with letter prefix or suffix, says Cell B2, and click the OK button.
Now the texts and numbers are split and placed beside original numbers with prefix or suffix. See below screenshot.
4. Select the split numbers, and click Data > Sort Smallest to Largest or Sort Largest to Smallest; and then check the Expand the selection option in the popping up Sort Warning dialog box, and click the Sort button. See below screenshots:


5. Now the numbers with letter prefix or suffix have been sorted as normal numbers sorting. You can delete the split text and numbers as you need.
Sort numbers with text/letter prefix or suffix by removing letters
This method will introduce Kutools for Excel’s Remove Characters utility to remove all non-numeric characters (including letter) and leave numbers only in cells. And then you can sort numbers with text / letter prefix or suffix easily.
Kutools for Excel - Packed with over 300 essential tools for Excel. Enjoy a full-featured 30-day FREE trial with no credit card required! Download now!
1. Copy all numbers with letter prefix or suffix, and then paste beside original numbers with letter prefix or suffix.
2. Keep selecting the pasted numbers, click Kutools > Text > Remove Characters, and then only check the Non-numeric option in the popping up Remove Characters dialog box, and click the Ok button. See below screenshot:
3. Now only numbers are left in the new column. Keep selecting these numbers, and click Data > Sort Smallest to Largest or Sort Largest to Smallest; and then check the Expand the selection option in the popping up Sort Warning dialog box, and click the Sort button. See below screenshots:


4. Delete the numbers as you need.
Demo: sort numbers with text/letter prefix or suffix in Excel
Articles
Sort full names by last name in Excel
Sort birthdays (dates) by month in Excel quickly
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
