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
 

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,719
Office Version
2010
Platform
Windows
Code:
Sheets(Array("01", "01", "03")).Visible = False
 

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,719
Office Version
2010
Platform
Windows
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.
 

Gavin T

Well-known Member
Joined
Mar 26, 2014
Messages
833
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
 

Forum statistics

Threads
1,082,629
Messages
5,366,645
Members
400,908
Latest member
currong

Some videos you may like

This Week's Hot Topics

Top