Hide/Unhide Worksheet Array?

thelostscott

Board Regular
Joined
May 7, 2010
Messages
226
Hi all,

I'm having trouble writing the code to hide & unhide an array of worksheets by clicking a "Button" (Macro assigned shape).

I though it would work with something like:

Code:
Sub Hide_Unhide_Workings()
Application.ScreenUpdating = False
 
If ActiveWorkbook.Sheets(Array("Download", "Pivot", "Download 2", "Download 3", "#WORKINGS#")).Visible = True Then
 
ActiveWorkbook.Sheets(Array("Download", "Pivot", "Download 2", "Download 3", "#WORKINGS#")).Visible = xlVeryHidden
    Else
        ActiveWorkbook.Sheets(Array("Download", "Pivot", "Download 2", "Download 3", "#WORKINGS#")).Visible = True
 
ActiveWorkbook.Sheets("Download 2").Activate
ActiveWorkbook.Sheets("Download 2").Range("E2").Select
 
End If
 
Application.ScreenUpdating = True
End Sub

But that freezes up when it tries to identify the array as visible.

Any ideas?
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I believe that making sheets visible can only be done one sheet at a time ( as it is in the Unhide dialog ).
 
Upvote 0
So would I have to go through each sheet in the array I specified above and do something like this:

Code:
Sub Hide_Unhide_BW_Workings()
Application.ScreenUpdating = False
 
If ActiveWorkbook.Sheets("Download").Visible = True Then
        ActiveWorkbook.Sheets("Download").Visible = xlVeryHidden
    Else
        ActiveWorkbook.Sheets("Download").Visible = True
End If
 
If ActiveWorkbook.Sheets("Download 2").Visible = True Then
        ActiveWorkbook.Sheets("Download 2").Visible = xlVeryHidden
    Else
        ActiveWorkbook.Sheets("Download 2").Visible = True
End If
 
Application.ScreenUpdating = True
End Sub
 
Upvote 0
You can loop, like this:
Code:
        myarray = Array("Download", "Pivot", "Download 2", "Download 3", "#WORKINGS#")
        For Each el In myarray
            If Sheets(el).Visible = True Then
                Sheets(el).Visible = xlVeryHidden
            Else
                Sheets(el).Visible = True
            End If
        Next
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,738
Members
452,940
Latest member
Lawrenceiow

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