Show/Hide Sheets Based on Cell Value

JohnSlider

New Member
Joined
Nov 23, 2015
Messages
41
Hello --

I have a workbook with multiple hidden worksheets. There are varying circumstances when the user would be expected to fill out any of them. Is there an easy way to make the workbook recognize if Cell A1 = XXXX, then sheets X, Y, Z are shown; if Cell A1 = YYYY, then Sheets A, X, Y are shown, etc.?

I would appreciate any help!

Thank you!
John
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
There is a possibility with a "change" macro

Here is a possibility to do it in the following code.

However, if there is too many sheets to hide, it will be useful to create a loop that hide every sheet then any show the good one.

Code:
Sub worksheet_change(ByVal Target As Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then
    If Target = "XXXX" Then
        Sheets("sheet x").Visible = True
        Sheets("sheet y").Visible = True
        Sheets("sheet z").Visible = True
        Sheets("sheet a").Visible = False
    ElseIf Target = "YYYY" Then
        Sheets("sheet a").Visible = True
        Sheets("sheet x").Visible = True
        Sheets("sheet y").Visible = True
        Sheets("sheet z").Visible = False
    End If
End If
End Sub
 
Upvote 0
Hi Roxxien.
I found this helpful to what i'm working on. I have 10 worksheets with 5 macros.
i just don't understand why the sub won't run, only 5 of my macros are available for testing.
why is this and how could i make it to run? Thanks
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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