hide a sheet until criteria in a different sheet in a range is met at least once.

AwesomeSteph

Board Regular
Joined
Aug 18, 2017
Messages
80
I have a workbook with 16 sheets.
If [H18:H44] in sheet3 has an "I" or a "VOS" ((these are from a data validation drop down menu and are the users only options) bigger problem there is a "V" option as well not sure if that is going to make it impossible since VOS has a V in it.) I want sheet13 to be visible, if that range is either blank or including a "V" I want sheet13 to be hidden. What I have does not work (it has worked on other spreadsheets I have created so I am lost). Please help.

this is the sheet3 microsoft excel object.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If [H18:H44].Value = "I" Or [H18:H44].Value = "VOS" Then
Sheets(13).Visible = True
    Else
        Sheets(13).Visible = False
    End If
End If
Application.ScreenUpdating = True
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Please clarify: You want every cell in H18:H44 filled with either "I" or "VOS", else hide sheet13?
 
Upvote 0
If all cells in H18:H44 are empty keep sheet13 hidden.
If all cells in H18:H44 are "V" keep sheet13 hidden.

If any cell in H18:H44 has a "I" or "VOS" I need sheet13 to be visible.
There may be combination of all 3, if there is even one "I" or "VOS" I need sheet13.
 
Upvote 0
Does this do what you want?
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If [COUNTIF(H18:H44,"I")] > 0 Or [COUNTIF(H18:H44,"VOS")] > 0 Then
    Sheets("Sheet13").Visible = True
Else
    Sheets("Sheet13").Visible = False
End If
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Maybe

Code:
Private Sub Worksheet_Change(ByVal Target As Range)If Intersect(Target, Range("H18:H44")) Is Nothing Then
Else
    If Application.CountIf(Range("H18:H44"), "I") > 0 Or Application.CountIf(Range("H18:H44"), "VOS") > 0 Then
        Worksheets(13).Visible = True
    Else
        Worksheets(13).Visible = False
    End If


End If


End Sub
 
Upvote 0
If the sheet name is "Sheet13" use Joemo' code, but if you are talking about the sheet codename try
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If [COUNTIF(H18:H44,"I")] > 0 Or [COUNTIF(H18:H44,"VOS")] > 0 Then
    Sheet13.Visible = True
Else
    Sheet13.Visible = False
End If
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Ok I may be going overboard here but I have another questions about this code.
So initially ALL the sheets in this workbook are hidden except for the first. The first sheet has required fields for users to fill out in order to see/use the other sheets. It is a boilerplate for required forms for the users new work. So all the sheets appear hidden at first. Once I use the code above it works while I am in VBA but once I save and try to test it out as soon as I fill in the required criteria in the boilerplate all the sheets are visible after that. Should I alter the code on the first sheet in order to achieve what I am trying to do by keeping some hidden or should I rearrange the sheet numbers to have all the sheets I want to remain hidden after the fact?
 
Upvote 0

Forum statistics

Threads
1,214,396
Messages
6,119,268
Members
448,881
Latest member
Faxgirl

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