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.
 

Some videos you may like

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,960
Office Version
  1. 365
Platform
  1. Windows
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
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,682
Office Version
  1. 2010
Platform
  1. Windows
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:

Watch MrExcel Video

Forum statistics

Threads
1,122,567
Messages
5,596,908
Members
414,110
Latest member
docops

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
Top