Macro to hide/unhide sheets based on date

A_Dub_Green

New Member
Joined
Dec 6, 2011
Messages
5
Hello, I see that there are several threads based on this topic, but being a novice Macro user, I don't feel comfortable using a previously posted code and trying to alter it for my purposes. I was wondering if anyone could assist me. I'm trying to set up a worksheet that will only show the tab for the current day. The tab will be named according to each day's date, and each worksheet will also contain the day's date in cell C1. I'm pretty sure that this is something simple, but like I said, I'm a novice. Any help would be greatly appreciated.

Thanks!
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
If you want the code to automatically run when the workbook is opened then place this code in the ThisWorkbook module:

Code:
Private Sub Workbook_Open()
    Dim ws As Worksheet
    Dim oName As Variant
 
    oName = Format(Date, "mm-dd-yy")
    For Each ws In Worksheets
        If Not ws.Name = oName Then ws.Visible = xlSheetHidden
    Next ws
End Sub

This requires that the sheets be named in the "MM-DD-YY format. If they are named differently then change that section of the code to match the format that the sheets are named.
 
Upvote 0
Thank you so much for the quick response. Unfortunately, when I pasted the code in, it didn't work. Perhaps there is something that I need to do before hand. I've renamed each tab in the "MM-DD-YY" format and put the date in each worksheet in cell C1. Right now, I have all the tabs showing, but I would only want the tab for 12-06-11 showing as that is today's date.
 
Upvote 0
Thank you so much for the quick response. Unfortunately, when I pasted the code in, it didn't work. Perhaps there is something that I need to do before hand. I've renamed each tab in the "MM-DD-YY" format and put the date in each worksheet in cell C1. Right now, I have all the tabs showing, but I would only want the tab for 12-06-11 showing as that is today's date.
 
Upvote 0
Do you want it to activate by a button or just automatically activate when you open the workbook? As it is put above it will automatically do it upon opening the workbook... so they only way to see if it works is to save the workbook, close it, and re-open it. If you want to test it using a button then put this code in a standard module:
Code:
Sub SheetDate
Dim ws As Worksheet
    Dim oName As Variant
 
    oName = Format(Date, "mm-dd-yy")
    For Each ws In Worksheets
        If Not ws.Name = oName Then ws.Visible = xlSheetHidden
    Next ws
End Sub

Then create a button, right click on it, assign macro, and click on "SheetDate".

I am running excel 03 and it seems to work fine with my test...
 
Upvote 0
I wanted it to activate by opening the workbook. I just opened it this morning, and I would have expected the 12-07-11 tab to be unhidden and the 12-06-11 tab to be hidden, but only the 12-06-11 tab is unhidden now.

I'm noticing that it works after I open it, and go to Tools-> Macro-> Macros-> Run, but not automatically when I open the file.
 
Upvote 0

Forum statistics

Threads
1,215,403
Messages
6,124,714
Members
449,182
Latest member
mrlanc20

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