Can you sort by more than 3 cryteria?

Barbarte

Board Regular
Joined
Dec 13, 2006
Messages
125
Hi everyone,

with code like this:

Code:
    Cells.Select
    Selection.Sort Key1:=Range("G2"), Order1:=xlAscending, Key2:=Range("M2") _
        , Order2:=xlAscending, Key3:=Range("H2"), Order3:=xlAscending, Header:= _
        xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
        xlSortNormal

can you add a 4th parameter by adding in:
Code:
Key4:=Range("I2"), Order4:=xlAscending,

so it looks like this:

Code:
Cells.Select
    Selection.Sort Key1:=Range("G2"), Order1:=xlAscending, Key2:=Range("M2") _
        , Order2:=xlAscending, Key3:=Range("H2"), Order3:=xlAscending-
        , Key4:=Range("I2")  ,Order4:=xlAscending,Header:= _
        xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
        xlSortNormal

will that work?
if not, is there another way to do it?

Thanks
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Nope, in excel 2002 you can't, it's limited to 3.
In the latest version of excel you can do as many as you like.
 
Upvote 0
In earlier versions, you have to do multiple passes, so you sort by the three least important first, then sort by the next 3 least important and so on. That way they should all end up in the right order. In your case, you could sort on fields 2,3 and 4 then do another sort on 1.
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top