Hiding sheets based on value

jUStPunkin

Board Regular
Joined
Mar 23, 2009
Messages
67
All,

As part of a larger project (and with some great help from this board), I've almost finished what I'm working on. I received this little bit of help earlier, where I want to hide some sheets and show others based on a specific criteria. I now realized that I actually have a second criteria which is important in determining what is hidden.

I have two values "G_CapturedAbove" and "G_TwoTiered". I have this little bit written to hide sheets based on the value of "G_Captured Above". What I need is to add is if "G_TwoTiered" = "Y", none of the sheets below are visible.

I feel like what I need to do is add another variable and set the visibility state based on both values, but I'm unsure how to do that. Can I add the variable and do an And function for each of those sheets? I tried, it didn't seem to work, but I may not have had it exactly correct.

VBA Code:
    Dim IsNo As Boolean
        IsNo = UCase(Range("G_CapturedAbove").Value) = "N"
        Sheets("Spouts").Visible = IsNo
        Sheets("Spouts2").Visible = Not IsNo
        Sheets("Redistribution Calculations").Visible = Not IsNo
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
You have 4 possible states
Book1
ABCDE
1Sheet Hidden
2G_CapturedAboveG_TwoTieredSpoutsSpouts2Redistribution Calculation
3NNVisibleHiddenHidden
4NYHiddenHiddenHidden
5YYHiddenHiddenHidden
6YNHiddenVisibleVisible
Sheet1


VBA Code:
    Dim IsNo As Boolean
     GCA = UCase(Range("G_CapturedAbove").Value) = "Y"
     GTT = UCase(Range("G_TwoTiered").Value) = "Y"
     If UCase(Range("G_TwoTiered").Value) = "Y" Then
        Sheets("Spouts").Visible = False
        Sheets("Spouts2").Visible = False
        Sheets("Redistribution Calculations").Visible = False
    Else  
        IsNo = UCase(Range("G_CapturedAbove").Value) = "N"
        Sheets("Spouts").Visible = IsNo
        Sheets("Spouts2").Visible = Not IsNo
        Sheets("Redistribution Calculations").Visible = Not IsNo
    End if
 
Upvote 0
Solution
You have 4 possible states
Book1
ABCDE
1Sheet Hidden
2G_CapturedAboveG_TwoTieredSpoutsSpouts2Redistribution Calculation
3NNVisibleHiddenHidden
4NYHiddenHiddenHidden
5YYHiddenHiddenHidden
6YNHiddenVisibleVisible
Sheet1


VBA Code:
    Dim IsNo As Boolean
     GCA = UCase(Range("G_CapturedAbove").Value) = "Y"
     GTT = UCase(Range("G_TwoTiered").Value) = "Y"
     If UCase(Range("G_TwoTiered").Value) = "Y" Then
        Sheets("Spouts").Visible = False
        Sheets("Spouts2").Visible = False
        Sheets("Redistribution Calculations").Visible = False
    Else 
        IsNo = UCase(Range("G_CapturedAbove").Value) = "N"
        Sheets("Spouts").Visible = IsNo
        Sheets("Spouts2").Visible = Not IsNo
        Sheets("Redistribution Calculations").Visible = Not IsNo
    End if
I see where this is going, and it makes sense to me. I am getting a variable not defined error; I'm assuming I have to define GCA and GTT?
 
Upvote 0
I see where this is going, and it makes sense to me. I am getting a variable not defined error; I'm assuming I have to define GCA and GTT?
I think I cut and pasted the wrong code. Try this

VBA Code:
    Dim IsNo As Boolean
    If UCase(Range("G_TwoTier").Value) = "Y" Then
        Sheets("Spouts").Visible = False
        Sheets("Spouts2").Visible = False
        Sheets("Redistribution Calculations").Visible = False
    Else
        IsNo = UCase(Range("G_CapturedAbove").Value) = "N"
        Sheets("Spouts").Visible = IsNo
        Sheets("Spouts2").Visible = Not IsNo
        Sheets("Redistribution Calculations").Visible = Not IsNo
    End if
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,643
Members
452,663
Latest member
MEMEH

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