Hide all sheets except one with VBA

Dokat

Active Member
Joined
Jan 19, 2015
Messages
302
Office Version
  1. 365
I have 20 sheets in the workbook and want to hide 19 of them with a click of a button.

Below code works but only hides the active sheet and not the other 18. Is there a better way to go about this?

Private Sub CommandButton1_Click()
With Sheets("Main Menu")
.Visible = True
.Activate
End With


Me.Visible = False

End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try

Code:
Private Sub CommandButton1_Click()
Sheets("Main Menu").Visible = True

For Each ws In WorkSheets
    If ws.Name <> "Main Menu" Then ws.Visible = False
Next ws
End Sub
 
Upvote 0
Now I can't get buttons to work and receiving "Can't Exit Design Mode because Control 'CommandButton1' can not be created" Error. Do you know what may cause this problem and how to fix it?

Thanks
 
Upvote 0

Forum statistics

Threads
1,212,931
Messages
6,110,745
Members
448,295
Latest member
Uzair Tahir Khan

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