Sort More than 3 criteria

G

Guest

Hi
I am trying to sort a data range with more than 3 criteria. I have tried
editing a recorded macro with 3 criteria and adding the 4th and it is not
working.

Selection.Sort Key1:=Range("C2"), Order1:=xlAscending, Key2:=Range("b2") _
, Order2:=xlAscending, Key3:=Range("D2"), Order3:=xlAscending,
Key4:=Range("h2"), _
Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1,
MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal
End Sub

Is there an error in my code or do I need a different approach?
Thanks
Matt
 
F

Frank Kabel

Hi
you have to do this in multiple steps:
1. Sort with the last criteria
2. Repeat sorting with the first 3 criteria
 
S

Sharad

Sort method can take max. of 3 sort field (key) arguments.
You can first sort with 1 key, and then repeat again with 3 more keys.

Sharad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top