1

I have a column with ID values, like these:

50
14G
44
2X
22

I would like to sort it by "digit value" using VBA, so I get a list like this

14G
22
2X
44
50

Since numbers should come before letters, and digits' relevance comes from their position. However, if I use Range().Sort I get a list like this:

22
44
50
14G
2X

Which is how Excel sorts it alphabetically. Is there a way to sort it the way I want it, short of writing a sort function myself?

1
  • You can add helper column with formula =""&A1 and sort using it. Commented Sep 16, 2015 at 11:02

1 Answer 1

3

If you format all of the values as Text you will be able to sort using the Sort numbers and numbers store as text differently option. This produces the results you are looking for.

        Sort Numbers as text

Of course, you will lose the benefit of dealing with true numbers and will have to watch out for lookups that are seeking a true number and not text-that-looks-like-a-number but as your values are already mixed, this might not be a bad thing.

Sign up to request clarification or add additional context in comments.

2 Comments

But how can I force a VBA script to view the cell's content as a Text?
Use VBA to convert them into text and put the Range.Sort method's DataOption:=xlSortNormal option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.