Excel VBA

Jamie9999

New Member
Joined
Apr 25, 2017
Messages
3
I have a simple code to hide and unhide sheets based on a drop down. the code keeps my "control" sheet visible at all times. i need to have other tabs visible as well. for example i want to have the "test" tab visible at all times. can someone please explain how can i add these additional tab exceptions to the code? I thought it was a simple Or statement but that is not working. Thanks.

Here is the code:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range
Dim ws As Worksheet

Set rng = Target.Parent.Range("office")

If Target.Count > 1 Then Exit Sub

If Intersect(Target, rng) Is Nothing Then Exit Sub

For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "control" Then ws.Visible = xlSheetHidden
Next ws
Sheets(Target.Value).Visible = True
End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Sheets(1).visible = true
sheets(2).visible = true
sheets(3).visible = true
.
.
.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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