Help With Mutli Sort

hank3rd

New Member
Joined
Apr 5, 2017
Messages
11
I am trying to get VBA/Macro to mutisort a file. I was able to record a macro and get it done on the sample sheet, but it would be limited to the defined rows. I tried coding it like below, but I am now getting a named argument error.

Columns("A:A").Select
ActiveWorkbook.Worksheets("RAW DATA").Sort.SortFields. _
Clear
ActiveWorkbook.Worksheets("RAW DATA").Sort.SortFields. _
Add2 Key:=Range("G1").Select
Range(Selection, Selection.End(xlDown)).Select , SortOn:=xlSortOnValues, Order:=xlDescending, _
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("RAW DATA").Sort.SortFields. _
Add2 Key:=Range("E1").Select
Range(Selection, Selection.End(xlDown)).Select , SortOn:=xlSortOnValues, Order:=xlDescending, _
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("RAW DATA").Sort.SortFields. _
Add2 Key:=Range("I1").Select
Range(Selection, Selection.End(xlDown)).Select , SortOn:=xlSortOnValues, Order:=xlDescending, _
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("RAW DATA").Sort
.SetRange Range("A:BG").Select
Range(Selection, Selection.End(xlDown)).Select
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom


I need to sort by 1. column G Descending, then 2, Column E Descending, and 3 Column I Descending.

The Columns will always be A through BG.

Can anyone help?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
try
Code:
With ActiveWorkbook.Worksheets("pcode").Sort
   .SortFields.Clear
   .SortFields.Add key:=Range("G1"), SortOn:=xlSortOnValues, order:=xlDescending, _
      DataOption:=xlSortNormal
   .SortFields.Add key:=Range("E1"), SortOn:=xlSortOnValues, order:=xlDescending, _
      DataOption:=xlSortNormal
   .SortFields.Add key:=Range("I1"), SortOn:=xlSortOnValues, order:=xlDescending, _
      DataOption:=xlSortNormal
   .SetRange Range("A1").CurrentRegion
   .header = xlYes
   .MatchCase = False
   .Orientation = xlTopToBottom
   .Apply
End With
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

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