Toggle Visibility of an Array of Worksheets

Gregory72

New Member
Joined
Jun 25, 2014
Messages
12
Is it possible to toggle the visibility of an array of worksheets rather than one worksheet at a time?
I know this code wouldn't work if you tried, but I'm thinking something like this:

Dim ShtNames as Variant
ShtNames = Array("01", "02", "03")
ShtNames.Visible = True

I know I could run a for loop through the array to show each sheet's visibility individually, but I was hoping that I could just do them at the same time. Any help would be appreciated.

Thanks
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Code:
Sheets(Array("01", "01", "03")).Visible = False
 
Upvote 0
There was a typo ...

Code:
Sheets(Array("01", "[COLOR="#FF0000"]02[/COLOR]", "03")).Visible = False

and that worked fine for me, but I should have used the correct enumeration:

Code:
Sheets(Array("01", "02", "03")).Visible = [COLOR="#FF0000"]xlSheetHidden[/COLOR]

The sheets all must be visible for it to work.
 
Upvote 0
Is it possible to toggle the visibility of an array of worksheets rather than one worksheet at a time? ...

If you want to toggle the worksheets between hidden and visible, try this.

Code:
Sub ToggleHidden()

    Dim wsToggle As Worksheet

    For Each wsToggle In Sheets(Array("01", "02", "03"))
        wsToggle.Visible = Not wsToggle.Visible
    Next wsToggle

End Sub
 
Upvote 0

Forum statistics

Threads
1,213,504
Messages
6,114,020
Members
448,543
Latest member
MartinLarkin

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