VBA - Hide Multiple Sheets Based On Date

foolishpiano

New Member
Joined
Aug 19, 2016
Messages
28
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

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
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,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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