Check boxes

pincivma

Board Regular
Joined
Dec 12, 2004
Messages
206
I found these two macros on the internet. The first macro works fine. I have no problem with that. What I want is also this: When the check box is ticked, I want the cell that the check box is in to turn green. The second macro only works on one check box. It does not work on all of them and I have 466 check boxes to deal with. Please help.

Sub Checkboxes()

i = 2
For Each cb In ActiveSheet.CheckBoxes
cb.LinkedCell = Cells(i, "C").Address
i = i + 1
Next cb
End Sub

Sub CheckBox1_Click()
Dim xRng As Range
Set xRng = Selection
If CheckBox1.Value = True Then
xRng.Interior.Color = vbGreen
Else
xRng.Interior.Color = xlNone
End If
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
For your first question, first add the following macro to your module...

Code:
Sub CheckBoxFormatting()


    Dim cb As CheckBox
    
    Set cb = ActiveSheet.Checkboxes(Application.Caller) 'Application.Caller returns the name of the checkbox that was checked
    
    If cb.Value = 1 Then
        cb.TopLeftCell.Interior.Color = vbGreen
    Else
        cb.TopLeftCell.Interior.Color = xlNone
    End If


End Sub
Then amend your macro so that it assigns the above macro to each checkbox....

Code:
Sub Checkboxes()


    Dim cb As CheckBox
    Dim i As Long
    
    i = 2
    For Each cb In ActiveSheet.Checkboxes
        cb.LinkedCell = Cells(i, "C").Address
        cb.OnAction = "CheckBoxFormatting"
        i = i + 1
    Next cb
    
End Sub
 
Upvote 0
I tried your code and it did not work. When the check box was clicked, it did not change color to green
 
Upvote 0
When you ran your Checkboxes() macro, did you make sure that the sheet containing your checkboxes was the active sheet?
 
Upvote 0
If you check/select a checkbox, does the linked cell display True?
 
Upvote 0
The linked cells do display True. But I messed up. I had conditional formatting on those cells that had the check boxes. I did not realize that that was causing the problem. When I took out the conditional formatting. The cells did turn green. My fault. SORRY!!
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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