Macro for hiding all active sheets exept one

chobanne

Active Member
Joined
Jul 3, 2011
Messages
269
Can someone please help me in this

I need macro in sheet 1 who will unhide sheet 2, hide sheet 1 and every other active sheet, so that only sheet 2 stay active and visible.

Thank you
 
Maybe it works on your excell version but that macro dont do that for me. It just hide me active sheet with macro button inside it and unhide sheet A2. I m using excel 2016

So i will explain again in some example with 7 sheets, but the number of them can vary

Lets suppose that before starting macro i have something like this

Sheet 1 - active and unhide, with macro button
Sheet 2 - hide
Sheet 3 - unhide
Sheet 4 - unhide
Sheet 5 - hide
Sheet 6 - unhide
Sheet 7 - unhide

After starting macro i want to have something like this

Sheet1 - hide, with macro button
Sheet2 - unhide and active
Sheet3 - hide
Sheet4 - hide
Sheet5 - hide
Sheet6 - hide
Sheet7 - hide

In another words i want only sheet2 to be unhide and active after starting macro, all all other sheets, were they visible or invisible before starting Macro, must be hidden
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
That is nothing like you asked for, you asked for every other active sheet but you are now saying only one sheet is active.
Try
VBA Code:
Sub chobanne()
   Dim Ws As Worksheet
   
   Sheets("Sheet2").Visible = xlSheetVisible
   For Each Ws In Worksheets
      If Ws.Name <> "Sheet2" Then Ws.Visible = xlSheetHidden
   Next Ws
End Sub
 
Upvote 0
Solution
That is nothing like you asked for, you asked for every other active sheet but you are now saying only one sheet is active.
Try
VBA Code:
Sub chobanne()
   Dim Ws As Worksheet
  
   Sheets("Sheet2").Visible = xlSheetVisible
   For Each Ws In Worksheets
      If Ws.Name <> "Sheet2" Then Ws.Visible = xlSheetHidden
   Next Ws
End Sub
thank you
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,946
Messages
6,122,401
Members
449,081
Latest member
JAMES KECULAH

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