Hiding Tabs
This is getting a little complicated for this forum, but give this code a try.
It must be copied to Sheet "Input". The "Yes" and "No" is case sensative.
Changing cell B93 on sheet "Input" will trigger the hiding or unhiding of
sheet "Sheet1".
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B93")) Is Nothing Then
If ThisWorkbook.Worksheets("Input").Range("B93").Valu e = "Yes" Then
ThisWorkbook.Worksheets("Sheet1").Visible = True
Else
ThisWorkbook.Worksheets("Sheet1").Visible = False
End If
End If
End Sub
Let me know if it works.
"jordanpcpre" wrote:
I tried this but it did not work:
Sub HideASheet()
If ThisWorkbook.Worksheets("b93").Range("b93").Value = "Yes" Then
ThisWorkbook.Worksheets("Sheet1").Visible = False
Else
ThisWorkbook.Worksheets("Sheet1").Visible = True
End If
End Sub
I wrote this in the "Input" sheet because that's where the "Yes"/"No" option
is. I need to hide the "Sheet1" sheet if "No" is selected in the "Input"
sheet. Thank you for the help and time.
"TomPl" wrote:
Sub HideA Sheet() --- leave it just as it is.
"ThisWorkbook" would not need to change as long as you copy the code into
the workbook the workbook you are working on.
"Sheet3" is in fact the name of the worksheet you are addressing and needs
to be in quotes.
"False" means that the referenced sheet will be hidden, "True" means the
referenced sheet will be visible.
You could put this in an if statement like this.
Sub HideA Sheet()
If ThisWorkbook.Worksheets("Where the Cell Is").Range("A3").value = "Yes" Then
ThisWorkbook.Worksheets("Sheet3").Visible = False
Else
ThisWorkbook.Worksheets("Sheet3").Visible = True
End If
End Sub
"jordanpcpre" wrote:
Tom, Thanks for the help. In the macro you showed me, what are the
variables? I'm new with macros and need a little help.
Sub HideASheet() ---does any reference go in the ()?
ThisWorkbook ---do I name this the current used tab name or use this name?
"Sheet3" ---I assume this is the worksheet I'm trying to hide
False ---is this a reference to some cell?
Remember, I'm trying to hide a seperate tab base whether or not a specific
cell is labled as "Yes" or "No".
Thank you!
"TomPl" wrote:
Something like this should do the job. You can link it to a worksheet event
or invoke it other ways. I like to create a text box, then assign the macro
to the text box. It is simple and flexible.
Sub HideASheet()
ThisWorkbook.Worksheets("Sheet3").Visible = False
End Sub
"jordanpcpre" wrote:
The validation box is on the same tab as the tab where I'm hiding the rows.
I would like to be able to hide a seperate tab. I can currently hide rows on
a tab that has a validation box. With that same code, can I hide a seperate
tab? Thanks!
"TomPl" wrote:
Where will this "validation box" be if you hide the tab?
"jordanpcpre" wrote:
Below is the code I've been using to hide or show a row based if "yes" or
"no" is selected in a validation box. This has been working. Now I would
like to also hide a Tab if "no" is selected. How can I had a tab in addition
to a row? Thanks!
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Range("171:186").EntireRow.Hidden = (LCase(Range("b92")) = "no")
End Sub
|