MACRO to hide all but one tab in excel

saraapple

Board Regular
Joined
Feb 3, 2020
Messages
165
Office Version
  1. 2010
Platform
  1. Windows
Hi,

I have several tabs in my worksheet that may be visible (depending on other macros) - I need to hide all but one "Paste HERE" - how do you do this?
The tabs I need to hide are changing so is there a code I can use to hide everything apart from the one sheet I want (Paste HERE).

Thanks
Sara
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
How about
VBA Code:
Sub saraapple()
   Dim Ws As Worksheet
   
   Sheets("Paste Here").Visible = xlSheetVisible
   For Each Ws In Worksheets
      If Not Ws.Name = "Paste here" Then Ws.Visible = xlSheetHidden
   Next Ws
End Sub
 
Upvote 0
1593455767651.png
1593455820316.png

Thank you for the help but I cant get it to work? Also the wrong tab is left open and my PASTE here is hidden?
 
Upvote 0
What is the name of the sheet that should remain visible.
 
Upvote 0
"PASTE here" is the tab - the sheet is called "Paragon_Orders_Checking Tool" - should I reference the sheet in the macro? Sorry probably a stupid question!
 
Upvote 0
You will need to Change both occurrences of "Paste here" in the code with the sheet name.
 
Upvote 0
Ok think this is me asking for the wrong thing!
The worksheet is called "Paragon_Orders_Checking Tool"
There are a total of 15 tabs on the sheet - I want a macro to hide all the tabs apart from the one called "Paste Here"
 
Upvote 0
The worksheet is called "Paragon_Orders_Checking Tool"
Do you mean workbook, or worksheet?
how about
VBA Code:
Sub saraapple()
   Dim Ws As Worksheet
   
   Sheets("Paste Here").Visible = xlSheetVisible
   For Each Ws In Worksheets
      If Not LCase(Ws.Name) = "paste here" Then Ws.Visible = xlSheetHidden
   Next Ws
End Sub
 
Upvote 0
That works THANK YOU!
Sorry long day....the workbook is Paragon_Orders_Checking Tool - I don't have a name for the worksheet.
Great advice as always thanks
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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