Hide Specific Sheets and Change Active

RandyD123

Active Member
Joined
Dec 4, 2013
Messages
289
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

What I am looking to do is put a macro button on my active sheet (PT Summary) that will hide that sheet and one other called (Sheet1) and then have a different sheet become the active one (ST Sum PM). Not sure how to go about that or if its possible?

Thank you for any help
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
You can get most of the code you need for this simply by using the Macro Recorder and record yourself performing these steps manually.

Here is what the cleaned up code will look like:
VBA Code:
Sub MyHideSheetMacro()

'   Make sure "ST Sum PM" sheet is visible and select it
    Sheets("ST Sum PM").Visible = True
    Sheets("ST Sum PM").Select
    
'   Hide other two sheets
    Sheets("Sheet1").Visible = False
    Sheets("PT Summary").Visible = False

End Sub
 
Upvote 0
Solution
You can get most of the code you need for this simply by using the Macro Recorder and record yourself performing these steps manually.

Here is what the cleaned up code will look like:
VBA Code:
Sub MyHideSheetMacro()

'   Make sure "ST Sum PM" sheet is visible and select it
    Sheets("ST Sum PM").Visible = True
    Sheets("ST Sum PM").Select
   
'   Hide other two sheets
    Sheets("Sheet1").Visible = False
    Sheets("PT Summary").Visible = False

End Sub
It errors out right away. Pop up saying "Reference must be to a macro sheet" And on another note, this button MUST be on my "ACTIVE SHEET" which is one of the two that will become hidden and make another one active.
 
Upvote 0
Worked perfectly for me when I tested it out.
What is the name of the module you have placed this code in?
It should be placed in a General module, and NOT one of the Sheet modules or the ThisWorkbook module.

Also, I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
You can get most of the code you need for this simply by using the Macro Recorder and record yourself performing these steps manually.

Here is what the cleaned up code will look like:
VBA Code:
Sub MyHideSheetMacro()

'   Make sure "ST Sum PM" sheet is visible and select it
    Sheets("ST Sum PM").Visible = True
    Sheets("ST Sum PM").Select
   
'   Hide other two sheets
    Sheets("Sheet1").Visible = False
    Sheets("PT Summary").Visible = False

End Sub
Ok got it working but the code ended up looking like this:

VBA Code:
Sub Macro1()
'
' Macro1 Macro
'
'
    Sheets(Array("Checkpoint Summary", "Sheet1")).Select
    Sheets("Checkpoint Summary").Activate
    ActiveWindow.SelectedSheets.Visible = False
    Sheets("Shift Summary PM").Select
    Range("A16:K21").Select
End Sub

Thank you anyway for try to help me...
 
Upvote 0
It looks like the issue is that the sheet names you gave in your original post were not correct!
Since we do not have access to your workbook, we can only program off the information you provide us.
 
Upvote 0

Forum statistics

Threads
1,215,011
Messages
6,122,677
Members
449,092
Latest member
tayo4dgacorbanget

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