I am trying to sort data in a spreadsheet by three different values:
- Column F - Values - Oldest to Newest
- Column B - Values - Smallest to Largest
- Column A - Values - Z to A
The code stops with an error on the .Apply section. I fear the cell selection is the issue.
Sub DatePartOrderSort()
'
' DatePartOrderSort Macro
'
'
LR = Cells(Rows.Count, "A").End(xlUp).Row
Range(Cells(5, "A"), Cells(LR, "J")).Select
'
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("Date Order").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Date Order").Sort.SortFields.Add Key:=Range( _
Cells(5, "A"), Cells(LR, "J")), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Date Order").Sort.SortFields.Add Key:=Range( _
Cells(5, "A"), Cells(LR, "J")), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Date Order").Sort.SortFields.Add Key:=Range( _
Cells(5, "A"), Cells(LR, "J")), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Date Order").Sort
.SetRange Range(Cells(5, "A"), Cells(LR, "J"))
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub