We help IT Professionals succeed at work.

vba hide tab according to cell value

BigWill5112 asked
I have 10 tabs each with a different manager's name.  My first sheet will serve sort of as a navigation sheet if you will.  Once they select their name on the navigation sheet I need a macro to hide all sheets whose name does not contain the manger name that was chosen.  I could proceed on my own but how do you search a sheet name for a certain name?
Watch Question

Finance Analyst
See similar example attached.

All sheets start off hidden until sheet name selected on first sheet.

Use the Format Sheet menu to unhide the sheets, change the names and the references on sheet 1 will also change. The rehide the sheets.

This uses the hyperlink method but the hyperlink requires the destination to be unhidden. The hyperlink goes to the same cell as the hyperlink but there is code on the sheet that recognises the hyperlink selection event and unhides and activates the relavant sheet.

Rob H

Ardhendu SarangiSr. Project Manager
Can you try the following code -

I have taken an example of two managers - John and Jane in this case.


Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim cel As Range, targ As Range
    Dim i As Integer
    Set targ = [F6]    'Watch these cells for changes
    Set targ = Intersect(targ, Target)
    If targ Is Nothing Then Exit Sub

    Application.ScreenUpdating = False
    Application.EnableEvents = False
    For i = 1 To Worksheets.Count
        If Worksheets(i).Name = targ.Value Or Worksheets(i).Name = "Summary" Then
            Worksheets(i).Visible = True
            Worksheets(i).Visible = False
        End If
    Application.ScreenUpdating = True
    Application.EnableEvents = True
    MsgBox ("Done!")
End Sub

Open in new window

Most Valuable Expert 2011
Awarded 2010

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.