Macro to Hide Sheets based on Tab Name

TrimFunction

New Member
Joined
Jan 9, 2018
Messages
18
I have several tabs/worksheets in my workbook with supporting data/lookups/values etc.

I usually unhide all worksheets with a simple macro to update my report, then manually hide them before I send out to an audience.

Is there functionality that will hide worksheets bases on the tab name?

example: if the worksheet/tab names were called "lookup.hid", "oss.hid", "2QData.hid", could a macro hide all sheets with ".hid" in the title?

thanks!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Maybe:
Code:
Sub HideCertainSheets()
Dim Sht As Worksheet
For Each Sht In ActiveWorkbook.Worksheets
    If Sht.Name Like "*.hid" Then Sht.Visible = xlHidden
Next Sht
End Sub
 
Upvote 0
How about
Code:
Sub Hideshts()
   Dim ws As Worksheet
   
   For Each ws In Worksheets
      If Right(ws.Name, 4) = ".hid" Then ws.Visible = xlSheetHidden
   Next ws
End Sub
 
Upvote 0
Thanks @JoeMo, this code worked perfectly!

good quote in your signature, here's another one that I really like:

"When I was a boy of fourteen, my father was so ignorant I could hardly stand to have the old man around. But when I got to be twenty-one, I was astonished at how much he had learned in seven years." - Mark Twain (allegedly)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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