Sub SortData()
Range("A2:FR29921").Sort Key1:=Range("C2"), Order1:=xlDescending, Key2:=Range("F2"), _
Order2:=xlAscending, Key3:=Range("D2"), Order3:=xlAscending, Key4:=Range("G2"), Order4:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
'Objective5m.Range("A1").AutoFilter
End Sub
Just to clarify -
Below is the code I am using to sort... When adding a Key4 it fails
Code:Sub SortData() Range("A2:FR29921").Sort Key1:=Range("C2"), Order1:=xlDescending, Key2:=Range("F2"), _ Order2:=xlAscending, Key3:=Range("D2"), Order3:=xlAscending, Key4:=Range("G2"), Order4:=xlAscending, Header:= _ xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _ xlSortNormal 'Objective5m.Range("A1").AutoFilter End Sub
Sub LNG2013()
With Range("A2:FR29921")
.Sort Key1:=Range("C2"), Order1:=xlDescending, Key2:=Range("F2"), _
Order2:=xlAscending, Key3:=Range("D2"), Order3:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
.Sort Key1:=Range("4th Key"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
End Sub
Yeah I just ended up adding a second sort, but it is limited to 3, doesn't make much sense to have such a short limit but... adding another works ok.
If you are using xl2007 or later (or for anyone who finds this post through a search)
Use SortFields.Add Method instead of
.Sort Key1:=, Key2:=, Key3:=
You can find instuctions for SortFields.Add Method in VBA Help.