Macro to hide all sheets except one

y2k

Board Regular
Joined
Feb 25, 2002
Messages
133
Is it possible to write a macro that will hide all sheets except one? If so, how do I go about it?

Thanx!!
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
I tried the code but didn't work. I changed sheet name to Main Menu and copy paste the code still no luck. Can anyone help me?
 
Upvote 0
Hi,

Say you wanted all sheets hidden except Sheet1 you can use this:-

Sub HideAllSheetsBarOne()
Dim sht As Object

For Each sht In Sheets
If sht.Name <> "Sheet1" Then
sht.Visible = xlSheetHidden
End If
Next sht

End Sub


If you want the sheets hidden so they can't be unhidden using Format, Sheet, Unhide change the xlSheetHidden bit it xlSheetVeryHidden. That way the sheets in question can only be unhidden using VBA.

HTH,
Dan

Hi Dan, I tried your code but I'm getting this error message:
Run-time error 1004:
Unable to set the Visible property of the Worksheet class

Note i did change the sheet name accordingly :)
 
Upvote 0
I figured it out :) I need to Unhide my target sheet first, otherwise, everything will be hidden which is not an acceptable task. Thanks!
 
Upvote 0

Forum statistics

Threads
1,215,267
Messages
6,123,963
Members
449,137
Latest member
yeti1016

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