Hi there, new here. :D
I've read through some of the other alphanumeric sorting posts but nothing seemed to help with my problem. I have something like this:
a1402
a1a21
a1235
z124
x1x2
x11a2
Not only are the letters and numbers mixed, but also of different lengths.
What it should sort as is:
a1a21
a1235
a1402
x1x2
x11a2
z124
But what it is doing is this:
a1235
a1402
a1a21
x11a2
x1x2
z124
aia should be BEFORE a12 and a14 etc...
I can make the cells all the same length by inserting numbers at the end but I can't get it to sort this right. Assuming I have hundreds more rows in my project so it's not so simple as manually reorganizing, is there anything I can do? Thnks!
Is the "prefix" always a single character or can it vary - eg xx1 etc...
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
I am heading off line shortly - or at least won't be posting much so figured I'd add something.
Based on your examples whereby alphas are only ever single char I think the "simplest" thing is to create a new key for sorting based on a split of the originals.
If we assume your values listed are in A1:A6 then
we can then combine B:E into a new key which we can use as sort keyB1: =LEFT($A1,MIN(FIND({1,2,3,4,5,6,7,8,9,0},$A1&1234567890))-1) copied down C1: =LOOKUP(9.99E+307,LEFT(1&REPLACE($A1,1,LEN($B1),""),ROW($1:$15))+0) copied down (add the 1 to cater for possibility of leading zeroes of first # in string) D1: =LEFT(REPLACE($A1,1,LEN($C1),""),MIN(FIND({1,2,3,4,5,6,7,8,9,0},REPLACE($A1,1,LEN($C1),"")&1234567890))-1) copied down E1: =(0&REPLACE(A1,1,LEN(C1&D1),""))+0 copied down
not very elegant I grant you...F1: =B1&TEXT(REPLACE(C1,1,1,""),"00000000")&IF(D1="","Z",D1)&TEXT(E1,"00000000")
in above we have assumed # are always <= 99999999
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
So far they seem to be single letters. Thanks for your help. I think I’m a bit more of a basic user than this though, where do I enter all of that? Surely it won’t all go into the formula bar? Can you give me a bit more of a step by step? Thanks!
Attached is a working example... it is as you state a non trivial exercise.
That being said others may have better ideas for you to pursue.
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
Thanks for your help! I finally figured out how to get it to work and it works beautifully.![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks