Forum Discussion
Radhish Kartha
Jun 12, 2018Copper Contributor
Need to hide sheet in a workbook based on the calendar day of the month
Hi Team, I have a sheet with 31 sheets corresponding to maximum 31 days in a month. I need to hide all the sheets that are in the future based on the calendar day of the month. For e:g If...
Matt Mickle
Jun 12, 2018Bronze Contributor
Hey Radhish-
Try adding a Workbook_Open event to the ThisWorkbook code module:
1. Paste this code to the ThisWorkBook code module
2. Save File as .xlsm
3. Open File (The code will run when macros are enabled and the associated sheets will be hidden)
Private Sub Workbook_Open()
Dim sht As Worksheet
Dim today As Integer
today = Day(Date)
For Each sht In ActiveWorkbook.Worksheets
If sht.Name <= today Then
sht.Visible = True
Else
sht.Visible = False
End If
Next sht
End Sub
Matt Mickle
Jun 14, 2018Bronze Contributor
Radhish-
Just wanted to follow up and see if you were able to get the solution to work and see if you might have any questions on how it works or how to implement it. Please feel free to post back to the Excel Community if you have anymore issues.