How to use the caller property of form controls like the form button to create a button that works like multiple buttons based on its captions.
Watch the training video:
Watch this video on YouTube.
Here’s the complete VBA code:
Sub usingCaller()
Application.ScreenUpdating = False
With ActiveSheet.Buttons(Application.Caller)
If .Caption = “SHOW ALL DETAILS” Then
With Range(“C5:I18”)
.EntireColumn.Hidden = False
.EntireRow.Hidden = False
End With
.Caption = “MONTHLY TOTAL SALES”
ElseIf .Caption = “MONTHLY TOTAL SALES” Then
Range(“D:H”).EntireColumn.Hidden = True
.Caption = “ITEMS YEARLY TOTALS”
ElseIf .Caption = “ITEMS YEARLY TOTALS” Then
Range(“D:G”).EntireColumn.Hidden = False
Rows(“6:17”).Hidden = True
.Caption = “SHOW ALL DETAILS”
End If
End With
Application.ScreenUpdating = True
End Sub
Further Reading: