Request for macro: hide worksheet based on cell-value in it's own worksheet

Giddo123

New Member
Joined
Dec 27, 2017
Messages
1
I have 20 worksheets. I need to hide those worksheets by macro according to a value in its own specific worksheet. For example,0=hide worksheet, 1=do not hide worksheet:
Worksheet 1, fieldA1=0 --> hide worksheet 1
Worksheet 2, fieldA1=1 --> do not hide Worksheet 1
Worksheet 3, fieldA1=1 --> do not hide Worksheet 3
Worksheet 4, fieldA1=0 --> hide worksheet 4
etc.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi & welcome to the board
How about
Code:
Sub HideSheets()

   Dim Ws As Worksheet
   
   For Each Ws In Worksheets
      If Ws.Range("A1") = 0 Then Ws.Visible = xlSheetHidden
   Next Ws

End Sub
 
Upvote 0
Hi & welcome to the board
How about
Code:
Sub HideSheets()

   Dim Ws As Worksheet
   
   For Each Ws In Worksheets
      If Ws.Range("A1") = 0 Then Ws.Visible = xlSheetHidden
   Next Ws

End Sub
On the off chance the OP is setting the value of A1 on the various sheets via VB code, you should probably set the sheets visibility to xlSheetVisible if cell A1 on the sheet is 1 as well. Assuming no sheets are VeryHidden, this should work...
Code:
Sub HideSheets()

   Dim Ws As Worksheet
   
   For Each Ws In Worksheets
      Ws.Visible = Ws.Range("A1").Value
   Next Ws

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,838
Members
449,193
Latest member
MikeVol

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