Sorting Alphanumeric data

DoggettsBG

New Member
Joined
Apr 13, 2017
Messages
7
I have a list of unit numbers for vehicles. Some are simple 1,2,3. Some are 16A, B-1, ME-1, FOB-1, etc. How can I format it to be in order. When I do the sort function it looks like this:
1
2
10
16
20
100
16a
B-1
B-10
FB-1
FB-10
FB-12
FB-4
FOB-1
FOB-2
IN-1
IN-10
IN-12
IN-13
IN-20
ME-2
OR-6
PU-1
PU-OW2
SD-2
SF-1
V-1

<colgroup><col></colgroup><tbody>
</tbody>


I need it to look like this:
1
2
10
16
16a
20
100
B-1
B-10
FB-1
FB-4
FB-10
FB-12
FOB-1
FOB-2
IN-1
IN-10
IN-12
IN-13
IN-20
ME-2
OR-6
PU-1
PU-OW2
SD-2
SF-1
V-1

<colgroup><col></colgroup><tbody>
</tbody>


Ive tried several formulas and either it sorts correct with the ones ending in "A" but makes it only go in order of the first number in the cell so 2 now comes after 19 etc. Or the other formula I used puts them in order with the 2 being after 3 but now all units with an "A" after are on the bottom



<colgroup><col></colgroup><tbody>
</tbody>
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Given your data, if you do something like the below

where column B2 has the formula: =IF(ISNUMBER(SEARCH("-",A2)),LEFT(A2,SEARCH("-",A2)-1),IF(NOT(ISNUMBER(RIGHT(A2,1)+0)),LEFT(A2,LEN(A2)-1),A2))
and C2 has the formula =IF(ISNUMBER(SEARCH("-",A2)),MID(A2,LEN(B2)+2,255),IF(NOT(ISNUMBER(RIGHT(A2,1)+0)),RIGHT(A2,1),""))

then your can sort all 3 column by B and C choosing Sort anything that looks like a number as a number



Excel 2013/2016
ABC
1RAWF1F2
211
322
41010
51616
62020
7100100
816a16a
9B-1B1
10B-10B10
11FB-1FB1
12FB-10FB10
13FB-12FB12
14FB-4FB4
15FOB-1FOB1
16FOB-2FOB2
17IN-1IN1
18IN-10IN10
19IN-12IN12
20IN-13IN13
21IN-20IN20
22ME-2ME2
23OR-6OR6
24PU-1PU1
25PU-OW2PUOW2
26SD-2SD2
27SF-1SF1
28V-1V1
Sheet2
 
Upvote 0
Do you see how in your example FB-4 is after FB-12? I need it to be before it.


you just need to adjust the formulas to return a real number

<b>Worksheet Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: rgb(255,255,255);border-collapse: collapse; border-color: rgb(187,187,187)"><thead><tr style=" background-color: rgb(218,231,245);color: rgb(22,17,32)"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">B2</th><td style="text-align:left">=IF(<font color="Blue">ISNUMBER(<font color="Red">SEARCH(<font color="Green">"-",A2</font>)</font>),LEFT(<font color="Red">A2,SEARCH(<font color="Green">"-",A2</font>)-1</font>),IF(<font color="Red">NOT(<font color="Green">ISNUMBER(<font color="Purple">RIGHT(<font color="Teal">A2,1</font>)+0</font>)</font>),--LEFT(<font color="Green">A2,LEN(<font color="Purple">A2</font>)-1</font>),--A2</font>)</font>)</td></tr></tbody></table></td></tr></table><br />

<b>Worksheet Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: rgb(255,255,255);border-collapse: collapse; border-color: rgb(187,187,187)"><thead><tr style=" background-color: rgb(218,231,245);color: rgb(22,17,32)"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">C2</th><td style="text-align:left">=IF(<font color="Blue">ISNUMBER(<font color="Red">SEARCH(<font color="Green">"-",A2</font>)</font>),IFERROR(<font color="Red">--MID(<font color="Green">A2,LEN(<font color="Purple">B2</font>)+2,255</font>),MID(<font color="Green">A2,LEN(<font color="Purple">B2</font>)+2,255</font>)</font>),IF(<font color="Red">NOT(<font color="Green">ISNUMBER(<font color="Purple">RIGHT(<font color="Teal">A2,1</font>)+0</font>)</font>),RIGHT(<font color="Green">A2,1</font>),""</font>)</font>)</td></tr></tbody></table></td></tr></table><br />


Excel 2013/2016
ABC
1RAWF1F2
211
322
41010
51616
616a16a
72020
8100100
9B-1B1
10B-10B10
11FB-1FB1
12FB-4FB4
13FB-10FB10
14FB-12FB12
15FOB-1FOB1
16FOB-2FOB2
17IN-1IN1
18IN-10IN10
19IN-12IN12
20IN-13IN13
21IN-20IN20
22ME-2ME2
23OR-6OR6
24PU-1PU1
25PU-OW2PUOW2
26SD-2SD2
27SF-1SF1
28V-1V1
Sheet2
 
Upvote 0
Hi!

Try the formula below in B2 and copy down:

=IF(COUNT(FIND("-",A2)),
TRIM(LEFT(SUBSTITUTE(A2,"-",REPT(" ",20)),20))&"-"&
IFERROR(TEXT(1*RIGHT(SUBSTITUTE(A2,"-",REPT(" ",20)),20),"000000"),TRIM(RIGHT(SUBSTITUTE(A2,"-",REPT(" ",20)),20))),
IFERROR(TEXT(1*LEFT(SUBSTITUTE(A2,"-",REPT(" ",20)),20),"000000"),
TEXT(1*MID(A2,1,SMALL(SEARCH(CHAR(ROW($65:$90)),A2),1)-1),"000000")&MID(A2,SMALL(SEARCH(CHAR(ROW($65:$90)),A2),1),20)))


ABCDEFG
1DataFormulaOrder NeedA-Z
210000011000001
320000022000002
41000001010000010
51600001616000016
62000002016a000016a
710000010020000020
816a000016a100000100
9B-1B-000001B-1B-000001
10B-10B-000010B-10B-000010
11FB-1FB-000001FB-1FB-000001
12FB-10FB-000010FB-4FB-000004
13FB-12FB-000012FB-10FB-000010
14FB-4FB-000004FB-12FB-000012
15FOB-1FOB-000001FOB-1FOB-000001
16FOB-2FOB-000002FOB-2FOB-000002
17IN-1IN-000001IN-1IN-000001
18IN-10IN-000010IN-10IN-000010
19IN-12IN-000012IN-12IN-000012
20IN-13IN-000013IN-13IN-000013
21IN-20IN-000020IN-20IN-000020
22ME-2ME-000002ME-2ME-000002
23OR-6OR-000006OR-6OR-000006
24PU-1PU-000001PU-1PU-000001
25PU-OW2PU-OW2PU-OW2PU-OW2
26SD-2SD-000002SD-2SD-000002
27SF-1SF-000001SF-1SF-000001
28V-1V-000001V-1V-000001
29
**********************************************************

<tbody>
</tbody>


I hope that the suggestion above helps.

Markmzz
 
Upvote 0
Hi!

Try the formula below in B2 and copy down:

=IF(COUNT(FIND("-",A2)),
TRIM(LEFT(SUBSTITUTE(A2,"-",REPT(" ",20)),20))&"-"&
IFERROR(TEXT(1*RIGHT(SUBSTITUTE(A2,"-",REPT(" ",20)),20),"000000"),TRIM(RIGHT(SUBSTITUTE(A2,"-",REPT(" ",20)),20))),
IFERROR(TEXT(1*LEFT(SUBSTITUTE(A2,"-",REPT(" ",20)),20),"000000"),
TEXT(1*MID(A2,1,SMALL(SEARCH(CHAR(ROW($65:$90)),A2),1)-1),"000000")&MID(A2,SMALL(SEARCH(CHAR(ROW($65:$90)),A2),1),20)))


ABCDEFG
1DataFormulaOrder NeedA-Z
210000011000001
320000022000002
41000001010000010
51600001616000016
62000002016a000016a
710000010020000020
816a000016a100000100
9B-1B-000001B-1B-000001
10B-10B-000010B-10B-000010
11FB-1FB-000001FB-1FB-000001
12FB-10FB-000010FB-4FB-000004
13FB-12FB-000012FB-10FB-000010
14FB-4FB-000004FB-12FB-000012
15FOB-1FOB-000001FOB-1FOB-000001
16FOB-2FOB-000002FOB-2FOB-000002
17IN-1IN-000001IN-1IN-000001
18IN-10IN-000010IN-10IN-000010
19IN-12IN-000012IN-12IN-000012
20IN-13IN-000013IN-13IN-000013
21IN-20IN-000020IN-20IN-000020
22ME-2ME-000002ME-2ME-000002
23OR-6OR-000006OR-6OR-000006
24PU-1PU-000001PU-1PU-000001
25PU-OW2PU-OW2PU-OW2PU-OW2
26SD-2SD-000002SD-2SD-000002
27SF-1SF-000001SF-1SF-000001
28V-1V-000001V-1V-000001
29
**********************************************************

<tbody>
</tbody>


I hope that the suggestion above helps.

Markmzz



Thanks that worked! I was driving myself nuts trying to put together the formula!!
 
Upvote 0

Forum statistics

Threads
1,214,821
Messages
6,121,762
Members
449,048
Latest member
excelknuckles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top