I've got a macro below, row 2 is the heading (in a table), and I'd like to (in priority) filter I2:
select the criteria UP, DOWN, LEFT, RIGHT,
sort Z-A (descending).
Then filter J2:
sort Largest to smallest
The macro is able to filter UP, DOWN, LEFT, RIGHT, but doesn't seem to sort from Z-A.
Any ideas why? Thanks!
select the criteria UP, DOWN, LEFT, RIGHT,
sort Z-A (descending).
Then filter J2:
sort Largest to smallest
The macro is able to filter UP, DOWN, LEFT, RIGHT, but doesn't seem to sort from Z-A.
Any ideas why? Thanks!
VBA Code:
Sub Breakthrough()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Main")
Dim LastRow As Long
LastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
ws.Range("I3").Formula = "=IF(AND(E3>C3,G3>E3,F3>D3,H3>F3),""UP"",IF(AND(C3>E3,E3>G3,D3>F3,F3>H3),""DOWN"",IF(AND(E3>C3,G3>E3,D3>F3,F3>H3),""RIGHT"",IF(AND(C3>E3,E3>G3,F3>D3,H3>F3),""LEFT"",""NO""))))"
Range("C3:L" & Range("A" & Rows.Count).End(xlUp).Row).FillDown
Range("I2").Select
Dim LastRow2 As Long
LastRow2 = Range("A" & Rows.Count).End(xlUp).Row
Selection.AutoFilter
ActiveSheet.Range("$A$2:$L$" & LastRow2).AutoFilter Field:=9, Criteria1:=Array( _
"DOWN", "LEFT", "RIGHT", "UP"), Operator:=xlFilterValues
ActiveWorkbook.Worksheets("Main").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Main").AutoFilter.Sort.SortFields.Add Key:=Range( _
"J2:J" & LastRow2), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Main").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Last edited: