JC wrote:
I recorded a 3 column sort macro and then followed the pattern to add keys 4 and
5 to the sort. This causes an Run-time error 1004 - Application-defined or
Object-defined error.
Other changes I made was to change Range("A538").Activate to Range("A1).Activate
and Range("A538").Select to Range("A1").Select as these positions will only
apply to this test file while A1 will apply whatever the size of the file.
The debug editor is highlighting the part starting with Selection.Sort..... and
ending with DataOption5:.....
I can't see anything in the code that looks wrong to me. This begs the
question - will Excel allow a 5 layer sort when its built in system only allows
nesting 3 layers?
Sub Sort()
'
' Sort Macro
' Macro recorded 1/02/2005 by John Clarke
'
' Keyboard Shortcut: Ctrl+s
'
Range("A1:P3678").Select
Range("A1").Activate
Selection.Sort Key1:=Range("H1"), Order1:=xlAscending, Key2:=Range("I1") _
, Order2:=xlAscending, Key3:=Range("J1"), Order3:=xlAscending, _
Key4:=Range("K1"), Order4:=xlAscending, Key5:=Range("A1"), _
Order5:=xlAscending, Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers, DataOption2:=xlSortTextAsNumbers, _
DataOption3:=xlSortTextAsNumbers, DataOption4:=xlSortTextAsNumbers, _
DataOption5:=xlSortTextAsNumbers
Range("A1").Select
End Sub
------------------
I don't know if what you've done is legal or not -- I've never tried it.
I suspect it's not legal since the manual version only allows three
levels.
Open up the VBA editor, put the cursor on the sort command and hit F1.
That brings up a help screen which implies only three levels can be done.
What I would do is simply what I said before. Do the sort twice -- once
with three levels and once with two. Just record it that way and then
go in to look at the code and see how they handled it.
It works. Try it.
Bill
|