launch an event when the value of a cell changes

robertvdb

Active Member
Joined
Jan 10, 2021
Messages
342
Office Version
  1. 2016
Platform
  1. Windows
I have this Sheet, where I want to change the backcolor of a command button, as soon as any values in range A2:A10 are CHANGED.

The issue with the code below is that the color changes as soon as any of these cells A2 through A10 are SELECTED. I don't want this, I only want a color change when the value changes.

Thanks.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i As Integer

i = Target.Row

If i >= 2 And i <= 10 Then
    
    If Target.Column = 1 Then
        CommandButton1.BackColor = RGB(100, 100, 0)
    End If
    
End If

End Sub
 

Attachments

  • change.png
    change.png
    9.7 KB · Views: 6
Then use a "Worksheet_Change" event procedure instead of a "Worksheet_SelectionChange".
The rest of the code should be mostly the same.
 
Upvote 0
Solution
You are welcome.
Glad I was able to help!
 
Upvote 0

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