Change Button Color Upon Click

carddard

Active Member
Joined
Aug 19, 2008
Messages
427
Hi guys,

I was wondering if it is possible to change the color of a command button after it's been clicked?

This is to allow the user to identify which buttons have already been clicked.

Thanks!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
You can always stick the instructions in the click event:

Private Sub CommandButton1_Click()
With CommandButton1
.Caption = "I've already been clicked"
.BackColor = &HFFFF&
.ForeColor = &H0&
End With
End Sub
 
Upvote 0
Hmm I found a loophole..
If I'm running an inputbox and I click cancel, the button changes colour anyway.

Any idea or alternatives I could use?
 
Upvote 0
Yes. Allow me to explain myself better.
In the command button, I call up some other subs.
In those subs, I have input boxes.

The code that Tom gave would change the colour as long as the user has clicked the button... So if the user clicks the button, the sub runs, and the input box comes out. If the user clicks cancel, it should exit entirely. Colour should not change.

Do you get what I'm trying to say?
 
Upvote 0
Sure, you could reset the command button's properties when cancel is clicked. Try something like this within the sub being called from the commandbutton:

(set the caption, backcolor, and forecolor as needed)
Code:
msg = Application.InputBox("Your message")
If msg = False Then
    With Sheet1.CommandButton1
        .Caption = ""
        .BackColor = ""
        .ForeColor = ""
    End With
    Exit Sub
End If
 
Upvote 0
Hi,

That would work if I'm putting my code in the command button.
But I'm calling a couple of other subs from my command button. That's why it's a bit complicated. =/
 
Upvote 0
Put that code in the sub that calls the inputbox, not the commandbutton code.

What is you sub currently doing if the user clicks cancel?
 
Upvote 0
I've tried putting the code in the sub that calls the inputbox. It doesn't work.
The sub continues to open a file and autofilter some stuff
 
Upvote 0

Forum statistics

Threads
1,213,563
Messages
6,114,332
Members
448,566
Latest member
Nickdozaj

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