Sorting numbers that end in letters

Jenifred

New Member
Joined
Jan 20, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I'm trying to sort a column that lists IDs that include letters and numbers. The issue is that some IDs are just numbers (450), while others end in letters (450A, 450B, etc.) I want it to sort as 450, 450A, 450B, 451, 452A, etc., but instead its sorting as 450, 451, 450A, 450B." I've tried telling it to sort as text, general, and as numbers. Any quick and easy solutions? The spreadsheet is small enough that I can live with it if the solution starts getting complicated.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Honestly - I found this in my personal macro-book document which i saved and used few years ago. Hope it helps !
Through UDF with the help of VBA Macro you can achieve it,

copy the below code in your Module,

VBA Code:
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

and go back to your sheet, type =num(input your cell) then press enter and drag till end of the row. Post using the sort method, you can sort it through ALT+D+S.

ValueSort
450450
450A450
451451
451A451
 
Upvote 0
Hi and welcome to MrExcel!

In an auxiliary column put the following formula. Then sort the data by the auxiliary column and then by the number column.

Dante Amor
ABC
1ANUMSAUX
22450450
34 450A450
45 450B450
53451451
66 452A452
Hoja2
Cell Formulas
RangeFormula
C2:C6C2=IF(ISNUMBER(SEARCH(RIGHT(B2,1),"0123456789")),B2,LEFT(B2,LEN(B2)-1))+0
 
Upvote 1
Honestly - I found this in my personal macro-book document which i saved and used few years ago. Hope it helps !
Through UDF with the help of VBA Macro you can achieve it,

copy the below code in your Module,

VBA Code:
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

and go back to your sheet, type =num(input your cell) then press enter and drag till end of the row. Post using the sort method, you can sort it through ALT+D+S.

ValueSort
450450
450A450
451451
451A451
Honestly - I found this in my personal macro-book document which i saved and used few years ago. Hope it helps !
Through UDF with the help of VBA Macro you can achieve it,

copy the below code in your Module,

VBA Code:
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

and go back to your sheet, type =num(input your cell) then press enter and drag till end of the row. Post using the sort method, you can sort it through ALT+D+S.

ValueSort
450450
450A450
451451
451A451
Thank you so much for the quick reply, but unfortunately this is way above my excel capabilities. But I may forward it to my IT department and ask them to implement it.
 
Upvote 0
Thanks for the quick reply. This seems much more suited to my capabilities, but I'm still having problems. My numbers are in column A, so where you have B2, should I change that to A2? And should I change where you have "ISNUMBER" to column heading that I actually use?
Hi and welcome to MrExcel!

In an auxiliary column put the following formula. Then sort the data by the auxiliary column and then by the number column.

Dante Amor
ABC
1ANUMSAUX
22450450
34 450A450
45 450B450
53451451
66 452A452
Hoja2
Cell Formulas
RangeFormula
C2:C6C2=IF(ISNUMBER(SEARCH(RIGHT(B2,1),"0123456789")),B2,LEFT(B2,LEN(B2)-1))+0
 
Upvote 0
My numbers are in column A, so where you have B2, should I change that to A2?
That's right, it should be like this:
Dante Amor
AB
1NUMSAUX
2450450
3 450A450
4 450B450
5451451
6 452A452
Hoja2
Cell Formulas
RangeFormula
B2:B6B2=IF(ISNUMBER(SEARCH(RIGHT(A2,1),"0123456789")),A2,LEFT(A2,LEN(A2)-1))+0


And should I change where you have "ISNUMBER" to column heading that I actually use?
No, you should not remove or change the IsNumber function, the IsNumber function is used in the formula to check if the last character of the "numbers" is a letter or is a number.
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,117
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top