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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
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,224,829
Messages
6,181,222
Members
453,024
Latest member
Wingit77

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