muhleebbin
Active Member
- Joined
- Sep 30, 2017
- Messages
- 252
- Office Version
- 365
- 2019
- 2016
- 2013
- 2010
- Platform
- Windows
- MacOS
- Mobile
- Web
Is there a better way to write the following code:
I have a 13th sheet (sheet1) where it contains the calculations on if a sheet should be hidden. Range E1:E12 calculates whether the sheet should be hidden or not and Range A1:A12 has the sheet names January-December. Also is this code better fit for Private Sub Workbook_Open()? No one will actually change anything or type anything in Sheet1 so that's why I think this might be a better fit for Workbook_Open. Basically trying to create a workbook that has monthly data that will automatically hide each prior month as the year progresses and opens to the current months sheet.
Thanks in advance for your assistance
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("E1") = "Yes" Then
Sheets("January").Visible = False
Else
Sheets("January").Visible = True
End If
If Range("E2") = "Yes" Then
Sheets("February").Visible = False
Else
Sheets("February").Visible = True
End If
'continues on for the remaining months
I have a 13th sheet (sheet1) where it contains the calculations on if a sheet should be hidden. Range E1:E12 calculates whether the sheet should be hidden or not and Range A1:A12 has the sheet names January-December. Also is this code better fit for Private Sub Workbook_Open()? No one will actually change anything or type anything in Sheet1 so that's why I think this might be a better fit for Workbook_Open. Basically trying to create a workbook that has monthly data that will automatically hide each prior month as the year progresses and opens to the current months sheet.
Thanks in advance for your assistance