Forum Discussion
Excel sort function
Gizwol79 Combining the "RE " and a number creates a text. So, now you are sorting texts and "RE 101" gets sorted after "RE 1009" just like "AB" would be sorted after "A" but before "B". To avoid this problem, all the codes should have the exact same structure. For example "RE nnnn.nn", meaning RE followed by 4 numbers, then a dot and then 2 more numbers.
But for now, to sort the rows back into their original order, you need to split the RE-codes into three segments, so that you get 3 columns one with only "RE ", another with numbers 1 to 1486 and a third one that may contain numbers 1 to 99.
First save a copy of your current workbooks and work on that one. Insert three columns to the right of the column with the (now incorrectly sorted) RE-codes. Copy the original RE-codes to the first inserted column and select it.
On the Data ribbon, choose Text to Columns. In step 1, choose "Delimited". Next. In step 2 choose "Space". Next. In step 3, in the preview window, click on the second column and select the Text button. Finish.
Now, do something similar with the second column that contains the nnn.nn part. This time, select "Other" in step 2 and enter a dot as the delimiter and in step 3 leave the data types at "General". Finish.
Now you'll have the three columns. On with "RE ", one with real numbers 1 to 1486 and one with real numbers 1 to 99. Let's give these three columns a header. Call them Part1, Part2 and Part3. Something like this:
Now select columns with Part2 and Part3. On the Home ribbon, Sort & Filter, Custom Sort. (Sort by) column Part2, Smallest to Largest. Add another sort level (Then by) column Part3, Smallest to Largest. OK. Now, the rows should be in their original places again.
If you want, you can now re-structure the project codes by combining the three columns like this: