Macro to run in all but one Worksheet

deb0578

Board Regular
Joined
Sep 8, 2010
Messages
62
Hello. I'm trying my best to write this simple code to run in all the worksheets but one. I've been searching on this forum for the answer, but can't get it correct as I keep getting error codes. Thanks for your help.


Dim Wksht As Worksheet
Dim cell As Range

For Each Wksht In ActiveWorkbook.Worksheets
If Wksht.Name <> "2012 Quarterly Summary" Then
For Each cell In Wksht.Range("B9:B50")
If (cell.Value = "" Or cell.Value = "ZZ") Then cell.EntireRow.Hidden = True
End If
Next cell
End If
Next Wksht
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
welcome to the board...

I think you have 1 too many End If's..

since This IF
If (cell.Value = "" Or cell.Value = "ZZ") Then cell.EntireRow.Hidden = True
Is all self contained (the action if True is written on the same line as the If Condition).
Then it does not require an End If

Try

Code:
Dim Wksht As Worksheet
Dim cell As Range

For Each Wksht In ActiveWorkbook.Worksheets
    If Wksht.Name <> "2012 Quarterly Summary" Then
        For Each cell In Wksht.Range("B9:B50")
            If (cell.Value = "" Or cell.Value = "ZZ") Then cell.EntireRow.Hidden = True
        Next cell
    End If
Next Wksht
 
Upvote 0
I made the change and it gives me a "Compiled Error: Expected End With."

Any suggestions? Thanks for your help!
 
Upvote 0
Oops! My bad ... I had several test programs running and was on the wrong one! It works great now. Thank you for all your help!
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top