Cerber1983
New Member
- Joined
- Aug 2, 2023
- Messages
- 10
- Office Version
- 365
- Platform
- Windows
Good morning!
I need someone's assistance with hide/unhide tabs of my workbook. Tabs are displayed or hidden based on drop-down value of a cell on the main page
Majority of states will be sharing same "Most States" tab and I am looking for VBA to hide/unhide tabs for special states.
For example: If I am selecting CA or WA (one of special states) in Cell C5 as per example above, I would like to get "CA Main" or "WA Main" tab to be displayed and "Most States" tab to be hidden. Or if it is NOT special state like CA or WA, "Most States" tab to be displayed and CA or WA to be hidden.
Below code seems to be working but the problem I am running into is that if I am selecting CA in cell C5, it brings both tabs up: "Most States" and "CA Main".
Below is VBA code that I have used. Please help!
Private Sub Worksheet_Change(ByVal Target As Range)
If [C5] = "CA" Then
Sheets("CA Main").Visible = True
Else
Sheets("CA Main").Visible = False
Sheets("Most States").Visible = True
End If
If [C5] = "CO" Then
Sheets("CO Main").Visible = True
Sheets("Most States").Visible = False
Else
Sheets("Most States").Visible = True
Sheets("CO Main").Visible = False
End If
I need someone's assistance with hide/unhide tabs of my workbook. Tabs are displayed or hidden based on drop-down value of a cell on the main page
Majority of states will be sharing same "Most States" tab and I am looking for VBA to hide/unhide tabs for special states.
For example: If I am selecting CA or WA (one of special states) in Cell C5 as per example above, I would like to get "CA Main" or "WA Main" tab to be displayed and "Most States" tab to be hidden. Or if it is NOT special state like CA or WA, "Most States" tab to be displayed and CA or WA to be hidden.
Below code seems to be working but the problem I am running into is that if I am selecting CA in cell C5, it brings both tabs up: "Most States" and "CA Main".
Below is VBA code that I have used. Please help!
Private Sub Worksheet_Change(ByVal Target As Range)
If [C5] = "CA" Then
Sheets("CA Main").Visible = True
Else
Sheets("CA Main").Visible = False
Sheets("Most States").Visible = True
End If
If [C5] = "CO" Then
Sheets("CO Main").Visible = True
Sheets("Most States").Visible = False
Else
Sheets("Most States").Visible = True
Sheets("CO Main").Visible = False
End If