Reputation: 5450
I have some code that (should) loop through all my worksheets and add an autofilter, however for some reason they're not showing up. When I turn on events, I can see that it is quickly being added then removed almost instantly. I'm assuming that this is because of something written earlier in my code, but I have too much code before this to evaluate what is causing the issue... Is there something I can add to guarantee the filters are added? Code:
Dim wsfixer As Worksheet
For Each wsfixer In ActiveWorkbook.Worksheets
With ActiveSheet
.AutoFilterMode = False
.Range("A:S").AutoFilter
End With
On Error Resume Next
Next
Upvotes: 1
Views: 50
Reputation: 23974
If you want to process the code on each worksheet, change
With ActiveSheet
to
With wsfixer
By using With ActiveSheet
the code within the With
block is being "shortcutted" to using the active sheet (e.g. .AutoFilterMode
is treated as ActiveSheet.AutoFilterMode
). So you are executing the same code over and over to the one active sheet.
Upvotes: 2