I'm pulling my hair out trying to figure out why this isn't working. I run the macro from Sheet2 and it just ends up clearing everything on that sheet rather than on the ws that's up in the rotation. It will work if I activate the ws first, but that doesn't seem like the best solution. Please help
Code:
Dim ws as Worksheet
Dim QueryCollection as Collection
Dim i as Integer, CIRows as Integer, CISectorColumn as Integer
'lots of prior code
For Each ws In ThisWorkbook.Worksheets
If (ws.Name = "A" Or ws.Name = "B" Or ws.Name = "C") Then
With Sheet1
Set QueryCollection = New Collection
For i = 6 To CIRows
If .Cells(i, CISectorColumn) = ws.Name Then
QueryCollection.Add (i)
End If
Next i
End With
ws.Activate 'Why do I need this line???
With ws
'Do a bunch of stuff
End With
End If
Next ws