Logical sort order in listbox

Logical sort order in listbox

Anonymous
Not applicable
259 Views
3 Replies
Message 1 of 4

Logical sort order in listbox

Anonymous
Not applicable
Any ideas on how to make the following list of items:

OP1
OP10
OP11
OP2
SCR

sort as:

OP1
OP2
OP10
OP11
SCR

in a listbox?

I want all of the digits in the string to be used in the sort, not digit by digit.

Should I break up the text characters vs digits and then use the Format function:

Format("1", "0#")
Format("2", "0#")
Format("10", "0#")

Or, how about regular expressions? I think I could do this rather easily with Perl regular expressions, but I'm not sure if the VBA equivalent can do this.

I'm thinking others have already tackled this issue and may have a solution.

Thanks.
0 Likes
260 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Its always been a problem, e.g. even with filenames in a folder Windows will sort them that way. I use names like: OP01, OP10. If you don't want to compare char-by-char, but numerical value, then you will have to break up the string like you suggested. You can use the Right() function to get at "numerical" portion. -- ---- Ed ---- "TomV" wrote in message news:3649070.1109192322566.JavaMail.jive@jiveforum2.autodesk.com... > Any ideas on how to make the following list of items: > > OP1 > OP10 > OP11 > OP2 > SCR > > sort as: > > OP1 > OP2 > OP10 > OP11 > SCR > > in a listbox? > > I want all of the digits in the string to be used in the sort, not digit by digit. > > Should I break up the text characters vs digits and then use the Format function: > > Format("1", "0#") > Format("2", "0#") > Format("10", "0#") > > Or, how about regular expressions? I think I could do this rather easily with Perl regular expressions, but I'm not sure if the VBA equivalent can do this. > > I'm thinking others have already tackled this issue and may have a solution. > > Thanks.
0 Likes
Message 3 of 4

Anonymous
Not applicable
As Ed mentioned, you may have to start from the right and use the IsNumeric test to see where the number stops
0 Likes
Message 4 of 4

Anonymous
Not applicable
Thanks guys.
0 Likes