Sorting Data where there is an alpha character at the end of the number

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,506
Office Version
  1. 2021
Platform
  1. Windows
I have account numbers the I need to sort as follows:

All the numbers ending in an X to be sorted first in ascending order (eg 25X, 31X etc), then all the other numbers must be sorted in asecending order for eg 1001, 1001A, 1001B, 1002 etc


Your assistance in resolving this will be most appreciated
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Create a helper column to sort by and use this formula:
=IF(RIGHT(A2,1)="X","1-","2-")&TEXT(IF(ISNUMBER(--RIGHT(A2,1)),A2,--LEFT(A2,LEN(A2)-1)),"0000")&IF(ISNUMBER(--RIGHT(A2,1)),"",RIGHT(A2,1))

This assumes account numbers can have up to 4 numeric positions at the front and either 1 or 0 alpha characters at the end.
 
Upvote 0
Hi Ron

Thanks for your help.This is a very clever formula It does the trick

Regards

Howard
 
Upvote 0

Forum statistics

Threads
1,202,984
Messages
6,052,914
Members
444,612
Latest member
FajnaAli

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