Active X button changing the caption of the button

Romano_odK

Active Member
Joined
Jun 4, 2020
Messages
380
Office Version
  1. 365
Platform
  1. Windows
Good evening,

What I would like to achieve is that when I push the active x button, the text in the button changes on based on the text that here is in it at the moment. What I also would want to happen is that a few other macro lines will execute.

So when the buttons says "Filter", change it to "Undo" and then execute a few other lines... when I click the button with "Undo", the text changes to "Filter" and execute a few other macro lines.

Can this be done?

Thank you for your time and efforts,

Kind regards,

Romano
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Like this (with the button named as CommandButton1):
VBA Code:
Private Sub CommandButton1_Click()
    Select Case CommandButton1.Caption
        Case Is = "Filter"
            CommandButton1.Caption = "Undo"
            'add more lines here
        Case Is = "Undo"
            CommandButton1.Caption = "Filter"
            'add more lines here
    End Select
End Sub
 
Upvote 0
Solution
Like this (with the button named as CommandButton1):
VBA Code:
Private Sub CommandButton1_Click()
    Select Case CommandButton1.Caption
        Case Is = "Filter"
            CommandButton1.Caption = "Undo"
            'add more lines here
        Case Is = "Undo"
            CommandButton1.Caption = "Filter"
            'add more lines here
    End Select
End Sub
Thank you, this does exactly what I need.
Have a nice day,

Romano
 
Upvote 0
Thank you, this does exactly what I need.
Have a nice day,

Romano
Oh one little question, can I combine a cell, say cell A1 which contains the value 3 to show in the button too. So say " Filter 3"

Thank you again for your time.
 
Upvote 0

Forum statistics

Threads
1,226,730
Messages
6,192,698
Members
453,747
Latest member
tylerhyatt04

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top