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?
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

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
 

Forum statistics

Threads
1,141,011
Messages
5,703,723
Members
421,311
Latest member
tanujath

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
Top