Toggle Button to hide / unhide multiple sheets

PVA0724

New Member
Joined
Apr 21, 2012
Messages
48
Hi

I'm new using the user forms so I have this procedure that hide / unhide to specific workshets...so I thought that if copy to the Private Sub of the ToggleButton will work the same...but it didn't...and here it is the code I used

Code:
 Private Sub ToggleButton1_Click()
 Dim ws As Worksheet
    For Each ws In Sheets(Array("ICP account Express List", "ICP Participants"))
        ws.Visible = (ws.Visible = False)
    Next ws

End Sub

Any idea how to get it, so that if I click the first time both worksheets will be hidden and in a second one visible

Thanks
 

Some videos you may like

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
You can use:

ws.Visible = Not ws.Visible

If you want it for general use, then remove the Private.

HTH,
 

PVA0724

New Member
Joined
Apr 21, 2012
Messages
48
Hi

Thanks for the prompt reply I did the change as follow

Code:
Dim ws As Worksheet
    [B][COLOR=#0000ff]For Each ws In Sheets(Array("ICP account Express List", "ICP Participants"))
[/COLOR][/B]       ws.Visible = Not ws.Visible
   Next ws

And now I'm getting Subscript out of range in the blue line. I only these worksheets to have them visible or not from the user form toggle button.
 

PVA0724

New Member
Joined
Apr 21, 2012
Messages
48
Hi Smitty

Yes, they are, what I did was to tested that as a producedure and it worked, so that's why I just copy it to the toggle button instruction, but it didn't work.
 

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
I don't know what to tell you. I just tested it and it works fine for me.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,318
Messages
5,600,921
Members
414,416
Latest member
Nobu

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
Top