Hi All,
Say I have 3 command buttons on a sheet (in real life I have 84). I created a class module which uses one simple sub, executing a command based on which button is clicked. Subsequently, the clicked button changes color. If you click another button, that button changes color. My challenge: when the second button is clicked, I want the first button to resume its original color.
For Simplicity's sake, I created a workbook with 3 command buttons and applied only the code needed to change the color. Please check out the code below, and the attached workbook and see if you can come up with a solution to my challenge.
General Module:
Dim Buttons3() As New dButtons
Private Sub Class_Init()
Dim Sh As Worksheet
Dim Obj As OLEObject
Dim ButtonCount As Integer
For Each Sh In ThisWorkbook.Worksheets
For Each Obj In Sh.OLEObjects
If TypeName(Obj.Object) = "CommandButton" Then
ButtonCount = ButtonCount + 1
ReDim Preserve Buttons3(1 To ButtonCount)
Set Buttons3(ButtonCount).ButtonGroup = Obj.Object
End If
Next Obj
Next Sh
End Sub
Class Module:
Public WithEvents ButtonGroup As CommandButton
Private Sub ButtonGroup_Click()
If ButtonGroup.BackColor <> RGB(225, 0, 0) Then
ButtonGroup.BackColor = RGB(225, 0, 0)
Else: ButtonGroup.BackColor = RGB(250, 250, 200)
End If
End Sub
Thanks!
Bookmarks