Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Sorting Alphanumeric Numbers

0
Created a list of my comics. The Edition column uses alphanumeric numbers and they do not sort correctly. Standard issue numbers are 0 through 900 ish. Annuals I start with A. Some special editions end with letters, I.E 1A, 0C etc. Example Comic A 78 Comic A 185 Comic A 258 Comic A 320 Comic A 321 Comic A 323 Comic A A16 Comic A A28 Comic B 1 Comic B 2 Comic B 3 Comic B 4 Comic B 5 Comic B 1A One sort method keeps 78 before 100 number string but puts 1A is after 5. Another sorting method puts the 1A after the 1 but will put 78 after 323. Need to figure out a way to sort everything the same. Thanks to anyone who can solve this challange.
Answer
Discuss

Answers

0

You could create two new columns and get the text into one and the numbers into the other one and then sort those two columns how you want and then hide the columns.

It looks like there might not be a standard naming/numbering convention so you might not be able to use regular text extraction functions, but if I'm wrong, try using the LEFT() and RIGHT() functions.

Otherwise, here are just a couple of the results on this topic from a search on TeachExcel (search bar at the top of every page):

Simple Excel Function to Extract a Word or Text from a Cell

Get the Number(s) Out of a Cell that Contains Both Text and Numbers in Excel - UDF

Some search results lead to pages with downloadable files that show how to do things, but I haven't got the videos linked-up to all of them yet.

Discuss
0

In principle, there are two ways of sorting, numeric and alphabetical. In numeric sorting 12 will follow 2 while the alphabetical sequence has "12" before the "2". Windows Explorer features a hybrid of these where leading numbers in alphanumeric file names are sorted numeric and only the remaining portions of file strings alphabetical. By this method "2xyz" will come before "12xyz" but "12xyz12" will come before "12xyz2".

Some of these problems can be overcome by inserting zeroes into an alphabetical sort. "xyz02" will sort before "xyz12" because 0 will sort before 1. However, in this kind of solution you are already deep into ASCII sorting which is naturally different from numeric sorting. The ASCII code for 0 = 48 and ASC("1") = 49. Therefore "0" sorts before "1" and there is no cure for that.

In practise, if you need to sort two parts of a string by different methods, you need to create two parts of the string, manipulate each part so that it sorts as you need it, then join the strings and sort on the joined strings. If you are good at VBA you can do that behind the scenes, incolumns that are specially created for this purpose and removed when done. If you [have to] prefer a simpler solution you would opt for hidden columns to control the sorting.

Either way, you should start by clarifying your rules. I think it's also important to understand the limitations of sorting before creating the rules - a point at which I sense you might be stuck - which is why I explained the technical difference between numeric and ASCII sorting. To recpature: each character, including numeric ones, has an ASCII code. Alphabetical or ASCII sorting dissects the string into character code numbers and sorts by their value.

Discuss


Answer the Question

You must create an account to use the forum. Create an Account or Login