I am looking for Excel VBA to change the caption on an Excel command button on the fly. The default caption should be "Show Difference" and should change to Show All when the filter is applied.
This is what I have so far.
Sub ShowDifference()
Dim cmdButton As CommandButton
'Breaks Here
Set cmdButton = ActiveSheet.Shapes("cmdShowDif")
If cmdButton.Caption = "Show Difference" Then
ActiveSheet.ListObjects("qryDifference").Range.AutoFilter Field:=4, _
Criteria1:=Array("<>0.00"), Operator:=xlAnd
cmdButton.Caption = "Show All"
Else
ActiveSheet.ListObjects("qryDifference").Range.AutoFilter Field:=4
cmdButton.Caption = "Show Difference"
End If
End Sub
It breaks on the name of the sub. Why?