VBA Multi-level Sorting

default_name

Board Regular
Joined
May 16, 2018
Messages
172
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
I have seen several examples of multi-level sorting online, but I am struggling to find a method that works best for my needs.
I am trying to sort all of the data on sheet1 (the data spans from columns A to R).

Here is what I currently have (including the order in which I am trying to sort the data on):
VBA Code:
Sheets("sheet1").Range("A1:R" & Sheets("sheet1").Range("A1").End(xlDown).Row).Sort _
key1:=Sheets("sheet1").Range("A:A"), order1:=xlAscending, _
key2:=Sheets("sheet1").Range("G:G"), order2:=xlAscending, _
key3:=Sheets("sheet1").Range("F:F"), order3:=xlAscending, _
key4:=Sheets("sheet1").Range("B:B"), order4:=xlAscending, _
key5:=Sheets("sheet1").Range("M:M"), order5:=xlAscending, _
Header:=xlYes

I get an error when I attempt this. I have stepped through it and am realizing that it only works with 3 keys. I need it to work with 5.
I tried simply copying the code again with my remaining 2 columns, but that didnt work out so well. I need to sort all of the data together.

How can I make this work?
Thanks in advance
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
You cannot use that style of sort for more than three Keys. You will need to use the "new" style of sort.
You can use the macro recorder to get the basis of the code.

The other option is to sort on cols G & H and then sort again for cols A, B & F.
 
Upvote 0

Forum statistics

Threads
1,215,339
Messages
6,124,363
Members
449,155
Latest member
ravioli44

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