Macro for sheets

rhmkrmi

Active Member
Joined
Aug 17, 2012
Messages
348
Office Version
  1. 365
Platform
  1. Windows
Hi there,

I am looking for a macro that I can use o unhide sheets in a workbook.
I want to have three button in sheet1 for sheets 2, 3, an 4.
Sheets 2, 3, and 4 will be hidden and depending n which button we click on in sheet1, they unhide.
Also, when closing the workbook, I do not want to allow saving so that when the workbook is used next, sheets 2, 3, and 4 will be hidden.

Thank you.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
After you have created the buttons then you will need to assign each a macro
and use something like

Code:
ActiveWorkbook.Worksheets("Name of sheet goes here").visible=xlSheethidden

or if you know the codename of the worksheet then
Code:
codename.visible=xlsheethidden

For the button that will unhide use codename.visible=xlsheetvisible for each needed worksheet instead

Finally in the workbook before save event use the same code as the button that unhides
 
Last edited:
Upvote 0
Thank you, it is perfect.
How can I use codename.visible=xsheetisible to go to the sheet that it unhides?
At the moment it unhides the sheet but the cursor is still in sheet1 where I have the buttons.

Thanks.
 
Upvote 0
Something like
Code:
   cnData.Visible = xlSheetVisible
   Application.Goto cnData.Range("A1")
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,271
Members
452,628
Latest member
dd2

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