This code was working until the latest Windows update. Now it gives this error. (See attached pictures.) Do you have any thoughts as to why?
VBA Code:
Sub WorksheetLoop()
Dim WS_Count As Integer
Dim I As Integer
' Set WS_Count equal to the number of worksheets in the active workbook
WS_Count = ActiveWorkbook.Worksheets.Count
' Begin the loop
For I = 1 To WS_Count
Rows("1:1").Select
Selection.Delete Shift:=xlUp
Range("D:D,F:F").Select
Range("F1").Activate
Selection.Delete Shift:=xlToLeft
Range("A2:D251").Select
ActiveWorkbook.Worksheets().Sort.SortFields.Clear
ActiveWorkbook.Worksheets().Sort.SortFields.Add Key:=Range("A3:A12") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets().Sort.SortFields.Add Key:=Range("C3:C12") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets().Sort
.SetRange Range("A2:D12")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
' Go to next worksheet
Next I
End Sub
Attachments
Last edited by a moderator: