I have alphanumeric text in a column in Excel. I need to sort them in alphabetic order and also numerically.
The only way I could do this is by extract number to another column and then sort it, but it is not feasible for me as there same number may occur multiple times, there maybe multiple brackets and i need them to sort in alphabetic order too. I would like to know the VBA code also to automate this.
As you can see in the below image with A to Z sorting, "A05 [1][21]" came between "A05 [1][2]" & "A05 [1][3]", but I want it to be numerical order as shown in expected result..


Natural Sort via splitting
This approach
Split()function and executes a bubble sort andHelp procedure
FillSortCriteriaFurther hints
Splitting a string like
"A05-i [1][21]"by delimiter"["results in a zero-based array where the first token, i.e.token(0)equals"A05-i", the 2nd"1]"and the 3rd"21]". TheVal()function converts the bracket items to a numeric value ignoring non-numeric characters to the right.These tokens can be joined to a sortable criteria in the second column of the passed
array; as thearrargument has been passedByReference by default thus referring to thedataarray in the calling procedure, all entries change immediately the referringdataentries.Help procedure
NaturalSort(modified Bubblesort)