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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
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,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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