Hide Sheets Except with wild Card

menor59

Well-known Member
Joined
Oct 3, 2008
Messages
574
Office Version
  1. 2021
Platform
  1. Windows
Heres My Code...

Code:
Sub HideDatedSheets()
Dim wb As Workbook
Dim ws As Worksheet
Dim dDate As Date


Set wb = ActiveWorkbook
dDate = DateAdd("d", -Weekday(Date) + 1, Date)
For Each ws In wb.Sheets
    If Trim(ws.Name) = Format(dDate, "MMM DD, yyyy") Or _
        Trim(ws.Name) = Format(dDate + 7, "MMM DD, yyyy") Or _
        Trim(ws.Name) = Format(dDate - 7, "MMM DD, yyyy") Or _
        Trim(ws.Name) = Format(dDate - 14, "MMM DD, yyyy") Or _
        Trim(ws.Name) = Format(dDate - 21, "MMM DD, yyyy") Or _
        Trim(ws.Name) = Format(dDate - 28, "MMM DD, yyyy") Or _
        Trim(ws.Name) = "Union*" Or _
        Trim(ws.Name) = "Report*" Or _
        Trim(ws.Name) = "Blank" _
        Then ws.Visible = True Else ws.Visible = False
Next
End Sub

So what im trying to do is keep the Union* sheets shown as well as the Report* sheets shown. But i believe i have the code wrong because they are not showing up when the work book opens...

Trim(ws.Name) = "Union*" Or _
Trim(ws.Name) = "Report*" Or _

Thoughts??

Thank you in advance
 

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.
Just as a matter of curiosity, how many other sheets are there that you're hiding?
Is there any type of naming convention pattern to those sheets?
Might it be easier to test for the names of the sheets you DO Want Hidden?
 
Upvote 0
Understood. When its all said and done at the end of the year there could be 52 Sheets, Plus the Blank, Union Sheet, and the Report sheet. Hense up above i wanted to keep the last 5 weeks, Blank, Report and Union Viewable, but the wild card trigger might not be correct for the Report or Union sheets. They are in the work Book but they are hidden. the rest Hidden
 
Upvote 0
Try

Code:
        Left(Trim(ws.Name),5) = "Union" Or _
        Left(Trim(ws.Name),6) = "Report" Or _
 
Upvote 0

Forum statistics

Threads
1,214,823
Messages
6,121,777
Members
449,049
Latest member
greyangel23

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