View Single Post
 
Old 06-07-2018, 06:25 AM
Phil H Phil H is offline Windows XP Office 2010 64bit
Advanced Beginner
 
Join Date: Jun 2010
Posts: 81
Phil H is on a distinguished road
Default Modify Macro to Sort Last Four Characters

It would be much appreciated if someone could help modify this code to sort by the last four characters. Cells in the range contain entries of this format: N12345-12-A-1234. I need the code to sort by the last four numbers.

Again - appreciate any help.


Code:
Private Sub CommandButton23_Click()
    Range("B3:AA39").Select
    ActiveWorkbook.Worksheets("Current Status of CORs").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Current Status of CORs").Sort.SortFields.Add Key:= _
        Range("G4:G39"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
    With ActiveWorkbook.Worksheets("Current Status of CORs").Sort
        .SetRange Range("B3:AA39")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("A1").Select
End Sub
Reply With Quote