Macro to hide and unhide sheets by command button

zhoney786

New Member
Joined
Feb 22, 2011
Messages
5
Hi All

i have a workbook which contains multiple sheets. i want to put button on main sheet and want to display one sheet at a time.

like if i am on main sheet (all other sheet are hidden) and i am viewing all buttons from which i will decide which sheet to open (like sheet 1 or sheet 2) than main sheet will hide and sheet 1 or sheet 2 will open depending upon which button i have clicked.

secondly i want to place a main sheet button on every sheet which will take me back to main sheet and hide active sheet.

i will really greateful if somebody can help me with this macro i have tried alot of macros but not able to find a proper solution for this
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Good morning

I just tried out this method

Sub Button4_Click()
Worksheets(2).Visible = True
Worksheets(5).Visible = False
End Sub

obviously you would need to reverse the proceedure on sheet2
 
Upvote 0
thanks a lot mate but when i click on the button it gives me error 1004

Unable to set Visible property of the work sheet class

as i try to hide Main sheet and access another

please let me know what should i do now
 
Upvote 0
This is code i have written

this code is for one button i have put on Main sheet

Private Sub Commercial_Click()
Worksheets(1).Visible = False
Worksheets(2).Visible = True
Worksheets(3).Visible = False
End Sub

this code is for home button which i put on second sheet from which i want to access main sheet and hide all others


Private Sub CommandButton1_Click()
Worksheets(1).Visible = True
Worksheets(2).Visible = False
Worksheets(3).Visible = False
End Sub

now can you suggest why it is giving error not able to set visible property. i have put these codes on sheet level not on worksheet level
 
Upvote 0
If you only have three worksheets, you'll need to make sure one is visible at all times.
Reorder your code to make sure that happens and you should be fine.
 
Upvote 0
Thanks alot Mr Green 3 sheets is just an example sheets must be 10 to 12 thats why want a code on buttons which will naviagte to sheets and return to main sheet through button my code is not working it hides sheets first time after that it gives error which i have written above so please help me out with the code
 
Upvote 0
Instead of using false for hiding sheets, try using xlhidden.
Apart from that I can't see anything wrong.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,717
Members
452,939
Latest member
WCrawford

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