Sort data by 4 columns.. tweak needed

conoromuiri

New Member
Joined
Oct 31, 2011
Messages
25
Hi all,

I have some data that I was sorting previously by 3 different columns with the following code:

Code:
 Range("A2:R1500").Select
    Selection.Sort Key1:=Range("C3"), Order1:=xlAscending, Key2:=Range("A3"), _
        Order2:=xlAscending, Key3:=Range("R3"), Order3:=xlAscending, Header:= _
        xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
        xlSortNormal

Now I need to add another column to sort by... I tried adding 'key4' but it didn't seem to work for me...

Any ideas?
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi all,

I have some data that I was sorting previously by 3 different columns with the following code:

Code:
 Range("A2:R1500").Select
    Selection.Sort Key1:=Range("C3"), Order1:=xlAscending, Key2:=Range("A3"), _
        Order2:=xlAscending, Key3:=Range("R3"), Order3:=xlAscending, Header:= _
        xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
        xlSortNormal

Now I need to add another column to sort by... I tried adding 'key4' but it didn't seem to work for me...

Any ideas?

I think 3 is the limit, does this help?

http://www.mrexcel.com/archive/Data/1401.html

Or you could just add another sort:

Code:
Sub conoromuiri()

With Range("A2:R1500")

       .Sort Key1:=Range("C3"), Order1:=xlAscending, Key2:=Range("A3"), _
        Order2:=xlAscending, Key3:=Range("R3"), Order3:=xlAscending, Header:= _
        xlYes, 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
 
Upvote 0

Forum statistics

Threads
1,222,037
Messages
6,163,539
Members
451,843
Latest member
vitto

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