How to create a Macro to open and/or hide worksheets

Charles_

New Member
Joined
Dec 12, 2012
Messages
31
Hello,

I have tried searching for this on other threads to no avail.

I am trying to create a Macros where depending on the value of cell A2 (I have a data validation LIST type here), worksheet 1 or worksheet 2 will open.

For example, if the value on worksheet 1 cell A2 = "Yes" then hide worksheet 1 and 3 and open worksheet 2 only

if the value on worksheet 1 cell A2 = "No" then hide worksheet 1 and 2 and open worksheet 3 only.


I do not need to copy and paste any data across - worksheets 1 & 2 are completed

Thanks in advance.
 

Some videos you may like

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Charles_

New Member
Joined
Dec 12, 2012
Messages
31
Hello,

I have found a solution for this issue by creating a button and defining the below

Private Sub CommandButton1_Click()


Sheets("Sheet2").Select
ActiveWindow.SelectedSheets.Visible = False


End Sub

Thanks
 

Watch MrExcel Video

Forum statistics

Threads
1,123,318
Messages
5,600,917
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