Each row of code less to be read enhances the performance of that code.
So the light versions
Code:
Private Sub ToggleButton1_Click()
Const Group1 = "D:P"
Range(Group1).EntireColumn.Hidden = Not Range(Group1).EntireColumn.Hidden
Me.ToggleButton1.Caption = IIf(Range(Group1).EntireColumn.Hidden, "Group 1 Unhide", "Group 1 Hide")
End Sub
Private Sub ToggleButton2_Click()
Const Group2 = "Q:AA"
Range(Group2).EntireColumn.Hidden = Not Range(Group2).EntireColumn.Hidden
Me.ToggleButton2.Caption = IIf(Range(Group2).EntireColumn.Hidden, "Group 2 Unhide", "Group 2 Hide")
End Sub
Private Sub ToggleButton3_Click()
Const Group3 = "AB:AI"
Range(Group3).EntireColumn.Hidden = Not Range(Group3).EntireColumn.Hidden
Me.ToggleButton3.Caption = IIf(Range(Group3).EntireColumn.Hidden, "Group 3 Unhide", "Group 3 Hide")
End Sub
Code:
Public Sub HideUnhide()
With ActiveSheet
Select Case Application.Caller
Case "btnGrp1":
.Columns("D:P").Hidden = Not .Columns("D:P").Hidden
Case "btnGrp2":
.Columns("Q:AA").Hidden = Not .Columns("Q:AA").Hidden
Case "btnGrp3":
.Columns("AB:AI").Hidden = Not .Columns("AB:AI").Hidden
Case "btnGrpAll":
.Columns("D:AI").Hidden = Not .Columns("D:AI").Hidden
End Select
End With
End Sub
Bookmarks