VBA Unhide sheets with condition

sbv1986

Board Regular
Joined
Nov 2, 2017
Messages
87
Hi all:

I have workbook Main.xlsx with 11 sheets (DATA, branch1, branch2, branch3, branch4, branch5, branch6, branch7, branch8, branch9, branch10).

In Cell A1 when I type "branch1", All sheets(branch2,....branch10) hide
when I type "branch2", All sheets(branch1, branch3,....branch10) hide .... ect

How can I do this by macro??

Thanks./.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
please copy/paste on Sheet Module of DATA sheet.
Hope this helps.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws  As Worksheet, wn As String
    If Intersect(Target, Range("A1")) Is Nothing Then
        Exit Sub
    Else
        wn = Range("A1").Value
        For Each ws In Worksheets
            If ws.Name <> wn And ws.Name <> "DATA" Then
                ws.Visible = False
            Else
                ws.Visible = True
            End If
        Next
    End If
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,697
Messages
6,126,269
Members
449,308
Latest member
VerifiedBleachersAttendee

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