Two different sort functions

ScottDarth

New Member
Joined
Jun 25, 2020
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I am attempting to write some vba code to do a multiple-column sort:

VBA Code:
    Dim ResLR As Long
    ResLR = 830 'Last row of the worksheet
    Worksheets("Resources").Range("A4:AE" & ResLR).Activate
    
    ActiveWorkbook.Worksheets("Resources").AutoFilter.Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Resources").AutoFilter.Sort.SortFields.Add2 Key:= _
        Range("C5:C" & ResLR), SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder _
        :="Current,Will exit,Future,Exit", DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Resources").AutoFilter.Sort.SortFields.Add2 Key:= _
        Range("Q5:Q" & ResLR), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
        :=xlSortNormal
    ActiveWorkbook.Worksheets("Resources").AutoFilter.Sort.SortFields.Add2 Key:= _
        Range("B5:B" & ResLR), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
        :=xlSortNormal
    ActiveWorkbook.Worksheets("Resources").AutoFilter.Sort.SortFields.Add2 Key:= _
        Range("A5:A" & ResLR), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
        :=xlSortNormal
    
    With ActiveWorkbook.Worksheets("Resources").AutoFilter.Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With

So far, so good. Now, I'm trying to do a second sort on some of the same data. I have determined the last row of the data (after it is sorted in the code above) that I wish to sort with a second method:

VBA Code:
LastWE = 813 'Last row of the sorted data I want to sort again
Worksheets("Resources").Range("A4:AE" & LastWE).Activate
        ActiveWorkbook.Worksheets("Resources").AutoFilter.Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Resources").AutoFilter.Sort.SortFields.Add2 Key:= _
            Range("Q5:Q" & LastWE), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
            :=xlSortNormal
        ActiveWorkbook.Worksheets("Resources").AutoFilter.Sort.SortFields.Add2 Key:= _
            Range("B5:B" & LastWE), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
            :=xlSortNormal
        ActiveWorkbook.Worksheets("Resources").AutoFilter.Sort.SortFields.Add2 Key:= _
            Range("A5:A" & LastWE), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
            :=xlSortNormal

This last bit does not seem to have any effect. What am I missing, or doing wrong?
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
I am a complete moron. But I will own that. I forgot to actually do the sort on the second set of code, as you can plainly see. When I added that, it works as expected.
 
Upvote 0

Forum statistics

Threads
1,215,493
Messages
6,125,126
Members
449,206
Latest member
burgsrus

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