PDA

View Full Version : Solved: Changing Text in Buttons



Opv
04-24-2010, 10:08 AM
I am experimenting with some buttons in my worksheets to call and activate various macros. I am wondering if there is a way similar to what can be done using Javascript to have one button which serves two purposes. By that I mean, if I currently have two buttons, one that has a text label, "Filter Data" and another which has a text label, "Show Data." These buttons call the "filterData" and "unfilterData" macros respectively.

Is there a way to use just one button? I mean, is there a way to cause the text lable to change from "Filter Data" to "Show Data" once the button is clicked and the filter macro has been activated, then if I click on the button again it would call the showData macro?

mdmackillop
04-24-2010, 10:24 AM
You could toggle them by hiding/unhiding

Private Sub CommandButton1_Click()
Call MyCode
Me.CommandButton2.Visible = True
Me.CommandButton1.Visible = False
End Sub

Bob Phillips
04-24-2010, 10:29 AM
Assign your button to this macro



Public Sub btnData()

With ActiveSheet.Buttons("Button 1")

If .Caption = "Filter Data" Then

Call filterData
.Caption = "Show Data"
Else
Call unfilterdata
.Caption = "Filter Data"
End If
End With
End Sub

Opv
04-24-2010, 11:12 AM
Thanks to both of you, mdmackillop and XLD. Both solutions are functional. XLD, I think your solution is closer to what I'm accustomed to doing in Javascript.

Thanks again,

Opv