I have an Excel worksheet with a large number of checkboxes. To improve visual clarity, I want the BackColor property of a given checkbox to change when it is checked (and revert back to white when unchecked). This should apply to each checkbox.
Here's my (very basic) macro to achieve this for an individual checkbox:
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
CheckBox1.BackColor = RGB(255, 0, 0)
ElseIf CheckBox1.Value = False Then
CheckBox1.BackColor = RGB(255, 255, 255)
End If
End Sub
But I cannot get it to work for all checkboxes without painstakingly adding this macro for each individual checkbox. Any help is greatly appreciated (and sorry if this is a very basic question, I'm fairly new to vba)!
The next solution refers to sheet ActiveX check boxes!
Subin a standard module:Workbook_Openevent, you should place the next code line inside it:Now, "SheetName" should be, of course, the name of the sheet containing the check boxes in discussion and
SheetCodeModuleshould be its code module name, which can be obtained using:in a testing sub and copying the return string, instead of
SheetCodeModule. When you open the sheet code module to copy the above code, you can see in the leftObject Exploreron the activated one something asSheet14 (SheetName).Sheet14is code module name...Now, it will work without preliminarily deactivate/activate the sheet in discussion. But, if an error occurs the array keeping the objects will lose its content and the actual
Activateevent is good to be maintained as a backup...Please, test it and send some feedback.