Hide all worksheets except the first one

antaeusguy

Board Regular
Joined
Mar 8, 2010
Messages
81
I have a number of worksheets in my workbook that changes everytime. It could have 10 worksheets one day and then 20 worksheets the other day. But which ever the condition is, I want to hide all worksheets except the first one Worksheets(1).

I know how to write a code that unhide all sheets, but I can't get to think how to skip the first one...

Code:
Sub HideAllSheets()
    Dim wk As Worksheet
    
    Application.ScreenUpdating = False
    
    For Each wk In Worksheets
        wk.Visible = xlSheetHidden
    Next wk
    
    Application.ScreenUpdating = True
End Sub

Any help is much appreciated! :)
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi,

try this

Code:
Sub HideAllSheets()
    Dim wk As Worksheet
 
    Application.ScreenUpdating = False
    For Each wk In Worksheets
    Select Case wk.Name
        Case "Sheet1" 'Change to your sheets name to keep visible
            'Do Nothing
        Case Else
        wk.Visible = xlSheetHidden
        End Select
    Next wk
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,561
Messages
6,179,522
Members
452,923
Latest member
JackiG

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