Need to hide sheets 3-10 when sheet 2 is active

djl0525

Well-known Member
Joined
Dec 11, 2004
Messages
1,240
I have a sheet called Main Menu. When it is the active sheet I want all of the sheets after it (to it's right) to become hidden. Sometimes it will become the active sheet because a button was clicked. Sometimes the user will get there by simply selecting it. That probably doesn't matter. I just want that when it is active all sheets to it's right are hidden.

Thanks in advance,
DJ
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
How about (pasted in the sheet's code):
Code:
Option Explicit

Private Sub Worksheet_Activate()
Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets
    If ws.Index > ActiveSheet.Index Then
        ws.Visible = xlSheetHidden
    End If
Next ws

End Sub


Does this work for you?
 
Upvote 0
Hey Barrie. I hope you are doing well.

It didn't work. I copied the code for the sheet Main Menu and when I activate that sheet the others do not hide.

DJ
 
Upvote 0
DJ, where did you put this code? Did you put it in the worksheet (i.e., right click on the worksheet, select "View code", and paste the code in that window)?
 
Upvote 0
I swear I double checked it before I said it didn't work. Upon triple check, no, it was not on the right sheet. It's on the right sheet now and it works!

Thank you!!

DJ
 
Upvote 0

Forum statistics

Threads
1,206,946
Messages
6,075,792
Members
446,158
Latest member
octagonalowl

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