I am trying to sort data in a worksheet based on two criteria in two columns that are not adjacent, but I keep getting the error "Expected End With" but End With is in the macro
Option Explicit
Sub tester()
Dim wks As Worksheet
Dim iRow As Long
For Each wks In ActiveWorkbook.Worksheets
With wks
With .Sort
.SortFields.Clear
.SortFields.Add Key:=Range("R:R"), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
.SortFields.Add Key:=Range("A:A"), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
.SetRange wks.Range("A:V")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.Apply
End With
End Sub
Attached is a sample worksheet
Bookmarks