Good morning. I'm trying to run some VBA code & I keep getting a compile error that highlights "sheetName" in the 6th line & says "For Each control Variable on arrays must be Variant".
Any help would be appreciated. Thanks!
Dim targetSheets(1 To 2) As String
Dim ws As Worksheet
Dim sheetName As String
targetSheets(1) = "Sales"
targetSheets(2) = "Revenue"
For Each sheetName In targetSheets ERROR IS ON THIS LINE
Set ws = ThisWorkbook.Worksheets(sheetName)
ws.Range("A:AD").Copy
ws.Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ws.Range("AG:BB").Delete Shift:=xlToLeft
ws.Rows("1:21").Delete Shift:=xlUp
ws.Range("F:AA").Delete Shift:=xlToLeft
ws.Range("$D$12:$D$5000").AutoFilter Field:=1, Criteria1:="yes"
ws.Range("D:E").EntireColumn.Hidden = True
Next sheetName
Any help would be appreciated. Thanks!
Dim targetSheets(1 To 2) As String
Dim ws As Worksheet
Dim sheetName As String
targetSheets(1) = "Sales"
targetSheets(2) = "Revenue"
For Each sheetName In targetSheets ERROR IS ON THIS LINE
Set ws = ThisWorkbook.Worksheets(sheetName)
ws.Range("A:AD").Copy
ws.Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ws.Range("AG:BB").Delete Shift:=xlToLeft
ws.Rows("1:21").Delete Shift:=xlUp
ws.Range("F:AA").Delete Shift:=xlToLeft
ws.Range("$D$12:$D$5000").AutoFilter Field:=1, Criteria1:="yes"
ws.Range("D:E").EntireColumn.Hidden = True
Next sheetName