Hide/Unhide Worksheets in Excel 365

Robert_Conklin

Board Regular
Joined
Jun 19, 2017
Messages
173
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I have the following sub that unhides all sheets in a workbook. I would like to use the button I assigned to the ribbon to hide all of the sheets when I click it again.

VBA Code:
Sub Unhide_Multiple_Sheets()
Dim ws As Worksheet

    'The For-Next is a loop that loops through
    'each sheet in the active workbook
    
    For Each ws In ActiveWorkbook.Worksheets
        'Set the visible property of the sheet (ws)
        'to visible (xlSheetVisible)
        
        ws.Visible = xlSheetVisible

    Next ws

End Sub

I tried copying the code, but changing the ws.Visible setting to xlSheetHidden, but the button does nothing when the sheets are visible. Any help would be awesome!
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
You can change to this code ....BUT, you cannot hide ALL sheets. One must be visible at all times or it will error

VBA Code:
Sub Unhide_Multiple_Sheets()
Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
       If ws.name<> "Sheet1" then
             ws.Visible = Not ws.Visible
       end if
    Next ws
End Sub
 
Upvote 0
Solution
That worked beautifully! I changed Sheet 1 to my Table of Contents sheet. Thank you very much for your assistance!!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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