Hello,
I would like to be able to sort a priority list using VBA. I would like to sort first by priority override, simple number sort that trumps anything else. Next I would like to do a "combination" sort. First sort on absolute need date, then on priority: high, medium, low. Then I would like to come back and sort on target date, then again on the priority for those tasks by high, medium, low. I tried some VBA code, but it isn't working at all.
I would like to be able to sort a priority list using VBA. I would like to sort first by priority override, simple number sort that trumps anything else. Next I would like to do a "combination" sort. First sort on absolute need date, then on priority: high, medium, low. Then I would like to come back and sort on target date, then again on the priority for those tasks by high, medium, low. I tried some VBA code, but it isn't working at all.
Code:
Sub Sorting()
Range("A1:H200").Select
ActiveWorkbook.Worksheets("Active").Sort.SortFields.Clear
' This sorts by Priority Override First
ActiveWorkbook.Worksheets("Active").Sort.SortFields.Add Key:=Range("A1"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
'This sorts by Absolute Need Date Second
ActiveWorkbook.Worksheets("Active").Sort.SortFields.Add Key:=Range("E1"), Order:=xlAscending, _
DataOption:=xlSortNormal
'This sorts by Priority
ActiveWorkbook.Worksheets("Active").Sort.SortFields.Add Key:=Range("B1"), SortOn:=xlSortOnValues, _
Order:=xlAscending, CustomOrder:="High,Medium,Low", DataOption:=xlSortNormal
'This sorts by Target Date Third
ActiveWorkbook.Worksheets("Active").Sort.SortFields.Add Key:=Range("D1"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
'This sorts by Priority
ActiveWorkbook.Worksheets("Active").Sort.SortFields.Add Key:=Range("B1"), SortOn:=xlSortOnValues, _
Order:=xlAscending, CustomOrder:="High,Medium,Low", DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Active").Sort
.SetRange Range("A1:H200")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
End Sub
Last edited by a moderator: