Conditional Hide Worksheets If cell F2 = 0

dtott

New Member
Joined
Mar 12, 2010
Messages
5
I would like to hide worksheets/tabs where F2 equals zero. Is there an easy way to do this for all worksheets. Each worksheet is named differently due to the way it is extracted out of the database.

Any help greatly appreciated.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
You can loop around the worksheets:

Code:
Sub Test()
    Dim ws As Worksheet
    For Each ws in Worksheets
        ws.Visible = Not (ws.Range("F2").Value = 0) 
    Next ws
End Sub

Note that at least one worksheet must be visible.
 
Upvote 0
"to do this for all worksheets" << you can't hide ALL worksheets.. at least 1 must be visible, say Sheet1.. (let's say it is (positionally) the left most off all your worksheets; AND it also is the Sheet that contains your cell F2.

Add to your Sheet1 Code Module

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet
If Target.Address = "$F$2" And Target.Value = 0 Then   'refers to Cell F2 on Sheet1
For i = ActiveWorkbook.Sheets.Count To 2 Step -1
Sheets(i).Visible = False
Next i
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,262
Members
452,627
Latest member
KitkatToby

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