duranimal86
New Member
- Joined
- Jul 24, 2019
- Messages
- 18
- Office Version
- 365
- Platform
- Windows
I have a workbook where 6 of the sheets are the same (a Summary sheet and 5 input sheets) and i want to be able to toggle showing/hiding two groups of rows across all 6 sheets. The two groups of rows (AM & PM) that I want to toggle between displaying/hiding (ex. If AM shown, then PM hidden and vice versa). I have added an ActiveX ToggleButton and got it to work for the Summary sheet, but can't get it to also work across the 5 input sheets (sheets are identical, so same rows to show/hide on all sheets). Note: There are other sheets in the workbook, so I need to specify sheets instead of just looping through all sheets.
Also, I am far from a VBA expert and can only piece together code from online, so any improvement suggestions are more than welcome. Just be warned that i might ask for an explanation to help me learn.
Also, I am far from a VBA expert and can only piece together code from online, so any improvement suggestions are more than welcome. Just be warned that i might ask for an explanation to help me learn.
VBA Code:
Private Sub ToggleButton1_Click()
Dim ws As Worksheet
Dim sheetList As Sheets
Set AM = Range("7:25")
Set PM = Range("26:44")
If AM.EntireRow.Hidden = True Then
AM.EntireRow.Hidden = False
PM.EntireRow.Hidden = True
ToggleButton1.Caption = "AM Meeting"
ToggleButton1.BackColor = vbYellow
Else
AM.EntireRow.Hidden = True
PM.EntireRow.Hidden = False
ToggleButton1.Caption = "PM Meeting"
ToggleButton1.BackColor = vbBlue
End If
End Sub