Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

macro that sorts a range from the last 5 characters 2

Status
Not open for further replies.

kragster

Technical User
May 9, 2007
55
DK
Hi,
I have a problem sorting a table from a column containing order numbers. The order numbers have the following format:
ABC00001 -> three letters succeded by 5 numbers. What I wanna do is sort the orders by the last 5 numbers, disregarding the three letters. Can anyone help me on the way here?
 
I would create a new column with the following formula
=right(A1,5) assuming your order numbers start in column A.
Copy this formula down for all your order numbers. You should now have a column with just the numeric parts of you order number. Now select all the data in you sheet and sort by this new column. You can record all the above actions in the macro recorder and that should at least give you a good starting point for your code.


In order to understand recursion, you must first understand recursion.
 
Code:
Sub Sort()
    Dim X   As Long
    
    For X = 1 To 65536
        If Range("A" & X) = "" Then Exit For
        Range("IV" & X) = Right(Range("A" & X), 5)
        
    Next
        
    Cells.Sort Key1:=Range("IV1"), Order1:=xlAscending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal
        
    Columns("IV").Delete Shift:=xlToLeft
End Sub

Everybody is somebodys Nutter.
 
Thank you both. Two excellent ways of doing this ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top