Using macro recorder to filter column C (by name) and then column E (by hour/date) I get the following code.
How can I optimize/reduce the amount of code while retaining the filter functionality?
Code:
Sub Macro1()
ActiveWorkbook.Worksheets("SheetA").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("SheetA").Sort.SortFields.Add2 Key:=Range("C2:C500") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("SheetA").Sort.SortFields.Add2 Key:=Range("E2:E500") _
, SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
"jan,feb,mar,apr,may,jun,jul,aug,sept,oct,nov,dec" _ 'to sort as hours and dates
, DataOption:=xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("SheetA").Sort
.SetRange Range("A2:I500")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
How can I optimize/reduce the amount of code while retaining the filter functionality?