Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.newusers
yip
 
Posts: n/a
Default sort alphanumeric data

I have data with mix number of digits and I like to sort them. Somehow, the
normal sorting process give me a not so desired result. Can anyone help?
A10
B100
A2
AA1
AD200
A1
The result I am looking for is:
A1
A2
A10
B2
B100
AD200

  #2   Report Post  
Posted to microsoft.public.excel.newusers
Niek Otten
 
Posts: n/a
Default sort alphanumeric data

I think your example wasn't exactly right' look at the B2 and AA1 entries.
But I assume you want to sort like the Excel row and column identifiers; I
also assume there will be two alpha characters at most

Go to the VB Editor (ALT+F11)
InsertModule
Paste these two functions in the code window:

Function PartOne(a As String) As String
Dim i As Long
For i = 1 To Len(a)
If Asc(Mid(a, i, 1)) < 47 Or Asc(Mid(a, i, 1)) 58 Then
PartOne = PartOne + Mid(a, i, 1)
End If
Next i
If Len(PartOne) = 1 Then PartOne = " " + PartOne
End Function
Function PartTwo(a As String)
Dim i As Long
For i = 1 To Len(a)
If Asc(Mid(a, i, 1)) = 47 And Asc(Mid(a, i, 1)) <= 58 Then
PartTwo = PartTwo + Mid(a, i, 1)
End If
Next i
PartTwo = CDbl(PartTwo)
End Function

If your data is in column a, put this in B1:

=PartOne(A1)

and in C1:

=PartTwo(A1)

Copy both down as far as needed.

Now sort on column B and C

--
Kind regards,

Niek Otten

"yip" wrote in message
...
I have data with mix number of digits and I like to sort them. Somehow, the
normal sorting process give me a not so desired result. Can anyone help?
A10
B100
A2
AA1
AD200
A1
The result I am looking for is:
A1
A2
A10
B2
B100
AD200



  #3   Report Post  
Posted to microsoft.public.excel.newusers
Niek Otten
 
Posts: n/a
Default sort alphanumeric data

47 should have been 48 and 58 should have been 57 in both cases

--
Kind regards,

Niek Otten


"Niek Otten" wrote in message
...
I think your example wasn't exactly right' look at the B2 and AA1 entries.
But I assume you want to sort like the Excel row and column identifiers; I
also assume there will be two alpha characters at most

Go to the VB Editor (ALT+F11)
InsertModule
Paste these two functions in the code window:

Function PartOne(a As String) As String
Dim i As Long
For i = 1 To Len(a)
If Asc(Mid(a, i, 1)) < 47 Or Asc(Mid(a, i, 1)) 58 Then
PartOne = PartOne + Mid(a, i, 1)
End If
Next i
If Len(PartOne) = 1 Then PartOne = " " + PartOne
End Function
Function PartTwo(a As String)
Dim i As Long
For i = 1 To Len(a)
If Asc(Mid(a, i, 1)) = 47 And Asc(Mid(a, i, 1)) <= 58 Then
PartTwo = PartTwo + Mid(a, i, 1)
End If
Next i
PartTwo = CDbl(PartTwo)
End Function

If your data is in column a, put this in B1:

=PartOne(A1)

and in C1:

=PartTwo(A1)

Copy both down as far as needed.

Now sort on column B and C

--
Kind regards,

Niek Otten

"yip" wrote in message
...
I have data with mix number of digits and I like to sort them. Somehow,
the
normal sorting process give me a not so desired result. Can anyone help?
A10
B100
A2
AA1
AD200
A1
The result I am looking for is:
A1
A2
A10
B2
B100
AD200





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
sort alphanumeric William Excel Discussion (Misc queries) 4 November 13th 06 11:11 PM
macro to sort data in worksheet by specific date joey Excel Discussion (Misc queries) 0 November 14th 05 07:59 PM
Unable to sort data in excel with cells containing if & hlookup MarcHere Excel Worksheet Functions 1 November 14th 05 04:06 PM
Sort data from 1 work sheet into another andrewgwatson Excel Worksheet Functions 0 June 1st 05 03:10 AM
Alphanumeric Sort Ray Excel Discussion (Misc queries) 5 May 20th 05 08:02 PM


All times are GMT +1. The time now is 02:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"