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

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
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
 
Upvote 0
Hi,
Please try this, and you will need to modify the sheet name.

<pre>
Sub test()
Dim sh As Worksheet
For Each sh In Worksheets
If sh.Name <> "Sheet1" Then sh.Visible = xlSheetHidden
Next
End Sub
</pre>
 
Upvote 0
On 2002-05-14 01:28, Colo wrote:
Hi,
Please try this, and you will need to modify the sheet name.<pre>
Sub test()
Dim sh As Worksheet
For Each sh In Worksheets
If sh.Name<> "Sheet1" Then sh.Visible = xlSheetHidden
Next
End Sub</pre>

What if you want to show them again?

_________________
Best Regards,<font color="black"><font size=+1><font color="blue"> Andreas<font size=1><font color="black"> using Excel 2000 - Windows 2000 prof.
This message was edited by sen_edp on 2002-05-14 01:36
 
Upvote 0
On 2002-05-14 01:35, sen_edp wrote:
On 2002-05-14 01:28, Colo wrote:
Hi,
Please try this, and you will need to modify the sheet name.<pre>
Sub test()
Dim sh As Worksheet
For Each sh In Worksheets
If sh.Name<> "Sheet1" Then sh.Visible = xlSheetHidden
Next
End Sub</pre>

What if you want to show them again?

_________________
Best Regards,<font color="black"><font size=+1><font color="blue"> Andreas<font size=1><font color="black"> using Excel 2000 - Windows 2000 prof.
This message was edited by sen_edp on 2002-05-14 01:36
<pre>
Sub test()
Dim sh As Worksheet
For Each sh In Worksheets
sh.Visible = True
Next
End Sub</pre>
 
Upvote 0
Hello Ivan,

Sorry I was not clear , i mean if you
use in the hide macro the xlveryhidden command, what you put in the unhide macro ?
 
Upvote 0
Thank you both very much, they work a treat. One final question (at least I hope it's the final question!). How can I tell it to unhide all of the sheets except one? It's the same one each time, namely 2003.

Thanks again, you've really been a great help
 
Upvote 0
On 2002-05-14 01:51, sen_edp wrote:
Hello Ivan,

Sorry I was not clear , i mean if you
use in the hide macro the xlveryhidden command, what you put in the unhide macro ?

Hi sen_edp Use the code I gave above...will
work even if xlveryhidden is set.
The const xlSheetveryhidden only hides it
from the Window > Unhide view.
 
Upvote 0
On 2002-05-14 01:54, y2k wrote:
Thank you both very much, they work a treat. One final question (at least I hope it's the final question!). How can I tell it to unhide all of the sheets except one? It's the same one each time, namely 2003.

Thanks again, you've really been a great help

<pre/>
Sub test1()
Dim sh As Worksheet
For Each sh In Worksheets
If sh.Name <> "2003" Then sh.Visible = xlSheetVisible
Next
End Sub
</pre>
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

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