VBA - Hide Multiple Sheets Based On Date

foolishpiano

New Member
Joined
Aug 19, 2016
Messages
25
Hello everyone! I currently have a workbook that is updated daily, and I've created a macro that captures the data and creates a new worksheet in the workbook dated with the current date. I've included what I think is all of the relevant code below (I'm happy to post the full code if that would be helpful as well):

Code:
' Create new worksheet with today's date
        Dim szTodayDate As String
        szTodayDate = Format(Date, "mmm-dd-yyyy")
        On Error GoTo MakeSheet
        Sheets(szTodayDate).Activate
        Exit Sub
MakeSheet:
        Sheets.Add , Worksheets(Worksheets.count)
        ActiveSheet.Name = szTodayDate
' Copy table data from FTS to new worksheet
    Worksheets("Table Data from FTS").ListObjects("Table_query__1").Range.Copy
    ActiveSheet.Range("A1").PasteSpecial Paste:=xlPasteValues

What I'm wondering is: is it possible to add to the code a line that will go through the workbook and hide all worksheets that were created over a week ago? The number of open worksheets is starting to become ridiculous, and does not need to be visible all of the time. This data is just for historical record to be recalled if needed.

Thank you all for your help!
 
That got it; thank you so much! I really appreciate all of your help. Out of curiosity, what is this new code doing that the other code wasn't doing?
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
It checks if the sheet name can be converted to a valid date & if it can, it converts it prior to checking if it's more than a week old.
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,093
Latest member
dbomb1414

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