ScottDarth
New Member
- Joined
- Jun 25, 2020
- Messages
- 3
- Office Version
- 365
- Platform
- Windows
I am attempting to write some vba code to do a multiple-column sort:
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:
This last bit does not seem to have any effect. What am I missing, or doing wrong?
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?