VBA Assistance - Hide / Unhiding a sheet based on cell contents

V L

New Member
Joined
Jul 25, 2024
Messages
14
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
Hello All: I have a workbook that contains multiple sheets . Certain sheets (not all) will have a value of 'closed' in C10. I would like to add some VBA that allows me to hide sheets that fit that criteria. Then, unhide them when necessary. Thank you for your assistance in advance...
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
We need a little more detail.

At what point do you want them evaluated for whether to hide them? Whenever the value in C10 changes to "closed"? Click a button? Open the file?

unhide them when necessary
When is it necessary? Are you expecting to unhide them manually or do you want code to do it? If you want code to do it, what event tells you to unhide them?

This will check all your sheets and hide the ones with "closed" in C10. But we need to wrap it in something that triggers it according to your answer to my first question.
VBA Code:
   Dim WS As Worksheet
   
   For Each WS In Worksheets
   
      If WS.Visible = xlSheetVisible And UCase(WS.Range("C10")) = "CLOSED" Then
         WS.Visible = xlSheetHidden
      End If
   
   Next WS
 
Upvote 0
Solution
We need a little more detail.

At what point do you want them evaluated for whether to hide them? Whenever the value in C10 changes to "closed"? Click a button? Open the file?


When is it necessary? Are you expecting to unhide them manually or do you want code to do it? If you want code to do it, what event tells you to unhide them?

This will check all your sheets and hide the ones with "closed" in C10. But we need to wrap it in something that triggers it according to your answer to my first question.
VBA Code:
   Dim WS As Worksheet
  
   For Each WS In Worksheets
  
      If WS.Visible = xlSheetVisible And UCase(WS.Range("C10")) = "CLOSED" Then
         WS.Visible = xlSheetHidden
      End If
  
   Next WS
TY for the assistance. I wanted to assign a button and run it as a macro...
 
Upvote 0
We need a little more detail.

At what point do you want them evaluated for whether to hide them? Whenever the value in C10 changes to "closed"? Click a button? Open the file?


When is it necessary? Are you expecting to unhide them manually or do you want code to do it? If you want code to do it, what event tells you to unhide them?

This will check all your sheets and hide the ones with "closed" in C10. But we need to wrap it in something that triggers it according to your answer to my first question.
VBA Code:
   Dim WS As Worksheet
  
   For Each WS In Worksheets
  
      If WS.Visible = xlSheetVisible And UCase(WS.Range("C10")) = "CLOSED" Then
         WS.Visible = xlSheetHidden
      End If
  
   Next WS
TY for the assistance. I wanted to assign a button and run it as a macro...
 
Upvote 0
You can take my code, wrap it in a sub, then assign it to a button.
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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