Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

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

Batch Separate text and numbers from one cell/column into different columns/rows

Kutools for Excel enhances its Split Cells utility and supports to batch separate all text characters and numbers of one cell/column into two columns/rows. Full Feature Free Trial 60-day!
ad split cell separate text numbers



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 - Combines more than 300 Advanced Functions and Tools for Microsoft Excel

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 - Combines more than 300 Advanced Functions and Tools for Microsoft Excel

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 - Combines more than 300 Advanced Functions and Tools for Microsoft Excel

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

 

In this Video, the Kutools tab and the Kutools Plus tab are added by Kutools for Excel. If need it, please click here to have a 60-day free trial without limitation!


Articles


Recommended Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 71%, and Help You To Stand Out From Crowd!

Would you like to complete your daily work quickly and perfectly? Kutools For Excel brings 300+ cool and powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) for 1500+ work scenarios, helps you solve 82% Excel problems.

  •  Deal with all complicated tasks in seconds, help to enhance your work ability, get success from the fierce competition, and never worry about being fired.
  •  Save a lot of work time, leave much time for you to love and care the family and enjoy a comfortable life now.
  •  Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands, and give you a healthy body.
  •  Become an Excel expert in 3 minutes, and get admiring glance from your colleagues or friends.
  •  No longer need to remember any painful formulas and VBA codes, have a relaxing and pleasant mind, give you a thrill you've never had before.
  •  Spend only $39, but worth than $4000 training of others. Being used by 110,000 elites and 300+ well-known companies.
  •  60-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years. Buy once, use forever.
  •  Change the way you work now, and give you a better life immediately!

Office Tab Brings Efficient And Handy Tabs to Office (include Excel), Just Like Chrome, Firefox, And New IE

  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Open and create documents in new tabs of same window, rather than in new windows.
  • Help you work faster and easily stand out from the crowd! One second to switch between dozens of open documents!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.

Be the first to comment.