Hiding multiple worksheets :VBA

ahugh01

New Member
Joined
May 19, 2016
Messages
9
Hello, I was hoping someone could help me with the best logic for hiding multiple excel tabs using VBA. I don't really mind the layout- just something functional. At any point new tabs can be added and I want to be able to use the TRUE FALSE logic within a worksheet instead of VBA.

Tab NameHide?
New Model PortfolioNew Model Portfolio.VisibleTRUE
ComplianceCompliance. VisibleFALSE

<tbody>
</tbody>
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Assuming you are going to use a worksheet to contain all these sheet names and you only need columns A & B, A= sheet name B = true or false.
Right click the worksheet and paste this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim sheetname As String
On Error GoTo 0
'change visible status
If Target.Column = 2 Then
sheetname = Cells(Target.Row, Target.Column - 1)
If Target = True Then
Sheets(sheetname).Visible = True
End If
If Target = False Then
Sheets(sheetname).Visible = False
End If
If UCase(Target) = "VERY" Then
Sheets(sheetname).Visible = xlSheetVeryHidden
End If
End If
End Sub

Allows you to also very hide the sheet.
 
Upvote 0
what does (ByVal Target As Range) mean?
What Roderick meant to say for installing his code is that you should right-click the tab at the bottom of the worksheet your data is located on, then click "View Code" from the popup menu that appears and copy/paste his code into the code window that opened up. Roderick's code is event code (in this case Change event code) and it executes automatically when you enter True, False or Very into a cell in Column B. The part you asked about is automatically handled by VBA... target is a cell reference to the cell that was changed. Note that to keep the event code active, you will need to save your workbook as a macro-enabled workbook.
 
Last edited:
Upvote 0
Is there another step after pasting it in? If I follow your instructions and then save the tabs are not hiding when they say FALSE?
 
Upvote 0
Is there another step after pasting it in? If I follow your instructions and then save the tabs are not hiding when they say FALSE?
The code only works when you "change" the value in the cell... entering Edit Mode (double-click the cell or press F2) and then pressing the Enter Key, pressing the Tab Key or clicking a different cell qualifies as "changing" the cell value.
 
Upvote 0
Hmm sorry Rick and ahugh, I didn't want to over explain so I under explained. Thanks Rick for helping out.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,694
Members
448,979
Latest member
DET4492

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