Unable to get visible property of sheets class

sdoppke

Well-known Member
Joined
Jun 10, 2010
Messages
647
Hi All, anyone see where im going wrong here?

Sais, i am unable to get the visible property of the sheets class?

Code:
Private Sub ToggleButton1_Click()
     'Toggles the To Do List sheet as hidden and unhidden
     
    Application.ScreenUpdating = False
     
    If Worksheets(Array("Week 1", "Week 2", "Week 3", "Week 4", "Week 5")).Visible = False Then
        Worksheets(Array("Week 1", "Week 2", "Week 3", "Week 4", "Week 5")).Visible = True
    ElseIf Worksheets(Array("Week 1", "Week 2", "Week 3", "Week 4", "Week 5")).Visible = True Then
        Worksheets(Array("Week 1", "Week 2", "Week 3", "Week 4", "Week 5")).Visible = False
    End If
     
    Application.ScreenUpdating = True
End Sub

I am trying to toggle hidden/unhidden the above sheets.

Thanks everyone in advance :)

sd
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
You need to loop

Code:
Private Sub ToggleButton1_Click()
     'Toggles the To Do List sheet as hidden and unhidden
     Dim ws As Worksheet
    Application.ScreenUpdating = False
     
    For Each ws In Worksheets(Array("Week 1", "Week 2", "Week 3", "Week 4", "Week 5"))
        ws.Visible = Not ws.Visible
    Next ws
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
You need to loop

Code:
Private Sub ToggleButton1_Click()
     'Toggles the To Do List sheet as hidden and unhidden
     Dim ws As Worksheet
    Application.ScreenUpdating = False
 
    For Each ws In Worksheets(Array("Week 1", "Week 2", "Week 3", "Week 4", "Week 5"))
        ws.Visible = Not ws.Visible
    Next ws
    Application.ScreenUpdating = True
End Sub


Love it!!, works great. Thank you so much for the help. :)
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,822
Members
452,946
Latest member
JoseDavid

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