VBA 2-Level Sort

flynavy

New Member
Joined
Mar 18, 2015
Messages
43
I'm looking for a very simple, straightforward, 2-level sort (VBA) of one sheet in a workbook. I'm a mid-level VBA coder (just started 6 months ago). I have done many sorts in VBA, and many 2-level sorts using Excel without VBA. I'm just looking for something elegantly simple using VBA (best practice). Let's say my sheet is A1:D100, and I want to sort ascending by column "A" first, and then by column "C", both ascending, and no headers.
I've seen many suggestions of many different forums, but I'm looking for, as I said, one that is "elegantly simple".
Thanks in advance for any help.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Code:
Range("A1:D100").Sort _
        key1:=Range("A1"), order1:=xlAscending, _
        Header:=xlNo, DataOption1:=xlSortTextAsNumbers, _
        MatchCase:=False, Orientation:=xlTopToBottom

        key2:=Range("C1"), order1:=xlAscending, _
        Header:=xlNo, DataOption1:=xlSortTextAsNumbers, _

        MatchCase:=False, Orientation:=xlTopToBottom
 
Upvote 0
Try
Code:
Range("A1:D100").Sort Key1:=Range("A1"), Order1:=xlAscending, _
                      Key2:=Range("C1"), Order2:=xlAscending, _
                      Header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
                      DataOption1:=xlSortNormal, DataOption2:=xlSortNormal
 
Upvote 0

Forum statistics

Threads
1,215,943
Messages
6,127,814
Members
449,409
Latest member
katiecolorado

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