Sort series alphaNumerically

sainathd

New Member
Joined
Aug 29, 2017
Messages
16
Hi, I have few rows of data

COL ACOL B
C10.2
C1000.3
C1010.4
C20.6
C2010.7
C2020.8
R30.9
R3011
R3022

<tbody>
</tbody>

Expected Result
COL ACOL B
C10.2
C20.6
C30.9
C1000.3
C1010.4
C2000.6
C2010.7
C2020.8
R30.9

<tbody>
</tbody>

Bottom Line I need to sort it as C1,C2,C3,.....C100,c101.. alphabet's first then numbers 1,2,3, sorting alpha numerically

Using build in SORT function I get C1,C100,C101.... I have like 500 rows as such, is there any way I could accomplish this with macro's?
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Dear Sainathd,

You can make use of helper formula , below formula will convert C1 to C001 , C2 to C002 depending on what is the max length available in a selected range. (in this case its 4 so it converts strings with less than 4 length to exactly 4 length by appending 0s before first number of string). Later you can sort helper column to achieve the desired result.

This is not the direct method but it will keep your data sanity intact. formula is assuming you have a data set in cells B2 to C10.

=LEFT($B2,SMALL(ISNUMBER(MID($B2,ROW(OFFSET($A$1,,,LEN($B2))),1)+0)*ROW(OFFSET($A$1,,,LEN($B2))),2)-1)&REPT("0",MAX(LEN($B$2:$B$10))-LEN($B2))&RIGHT($B2,LEN($B2)-SMALL(ISNUMBER(MID($B2,ROW(OFFSET($A$1,,,LEN($B2))),1)+0)*ROW(OFFSET($A$1,,,LEN($B2))),2)+1)

Also this is an array formula so press Ctrl+Shift+Enter and not enter only.
 
Upvote 0
If the assumption that the first character is always a Alpha character and there are no more than 3 digits, then you can get away with a simpler formula.
Code:
=LEFT(A2,1)&TEXT(VALUE(RIGHT(A2,LEN(A2)-1)),"000")
 
Upvote 0
If the assumption that the first character is always a Alpha character and there are no more than 3 digits, then you can get away with a simpler formula.
Code:
=LEFT(A2,1)&TEXT(VALUE(RIGHT(A2,LEN(A2)-1)),"000")
Based on your assumptions, this simpler formula would also work...

=LEFT(A2)&TEXT(MID(A2,2,3),"000")
 
Upvote 0

Forum statistics

Threads
1,216,115
Messages
6,128,919
Members
449,478
Latest member
Davenil

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