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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
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
 
Upvote 0

Forum statistics

Threads
1,213,544
Messages
6,114,249
Members
448,556
Latest member
peterhess2002

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