Hiding / Unhiding Sheets

Joker2

Board Regular
Joined
Mar 22, 2006
Messages
117
I have hidden all but 1 sheet in my workbook. Depending on the selection in cell E5 (I have created a validation list) on this sheet I would like the sheet with the same name to appear and to become the active sheet once the okay button is clicked.

If the user then manually selects the first sheet again I would like the sheet that appeared to hide itself again.

Is this possible at all?
 

Some videos you may like

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

wongm003

Board Regular
Joined
Aug 8, 2005
Messages
237
You can use this code in the worksheet that is always visible... This code will make the sheet visible as soon as the value in E5 is updated/changed. If you want to use your Okay button, move the code from the Worksheet_Chage Sub to your Okay button sub.

Code:
Private Sub Worksheet_Activate()
On Error Resume Next
    Dim strWS As String
    strWS = ActiveSheet.Name
    
    Application.ScreenUpdating = False
    'hide all sheets except active sheet
    For ws = 2 To ActiveWorkbook.Worksheets.Count
        If Sheets(ws).Name <> strWS Then Sheets(ws).Visible = False
    Next ws
    Application.ScreenUpdating = True

End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo normal_exit
    Dim strWS As String

    If Target.Address = "$E$5" Then
        strWS = Target
        Sheets(strWS).Visible = True
        Sheets(strWS).Activate
    End If

normal_exit:
    
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,113,811
Messages
5,544,437
Members
410,610
Latest member
renatha prado
Top