Forum Discussion
Inserting one checkbox and linking to multiple cells to trigger sums
Link check boxes to multiple cells at the same time using VBA code
If there are many check boxes to be linked to other cells, the first method will not work effectively. To link them to multiple cells at a time, you can apply the following VBA code. Please do the following:
- Go to your worksheet with the list of checkboxes.
- Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
- Click Insert> Module and paste the following code in the Module window box.
VBA code: Link check boxes to multiple cells at the same time
'1.Proposal...try...this solution..:)
Sub LinkChecks ()
i = 2
For Each cb In ActiveSheet.CheckBoxes
cb.LinkedCell = Cells (i, "B"). Address
i = i + 1
Next cb
End Sub
'2. Proposal Solution
Private Sub CheckBox1_Click()
'Code in die entsprechende Tabelle und Bereich anpassen!
If CheckBox1 Then
Range("D1:F1").Interior.ColorIndex = 3
Else
Range("D1:F1").Interior.ColorIndex = 10
End If
End Sub
- And then press F5 to run this code, all of the check boxes in the active worksheet have been linked to the cells. If you select the check box, the corresponding cell will be displayed TRUE If you clear a check box, the linked cell should be displayed FALSE.
Note: In the code above, i = 2, the number 2 is the first row of your check box and the letter B is the column position that you need to link the check boxes to. You can change them as you wish.
I hope I could help you a bit.
Nikolino
I know that I don't know (Socrates)
- Jacqueline28Jan 26, 2021Copper Contributor
Thank you so much for these insights. What is the 10 and 3 referencing in the formula?
Thanks!
- NikolinoDEJan 27, 2021Gold Contributor
What is the 10 and 3 referencing in the formula?
This property specifies a color as an index into the color palette.
Please see the following link where there is also a table with the colors.
ColorIndex property
https://docs.microsoft.com/en-us/office/vba/api/excel.colorindex
Hope I was able to help you.
Nikolino
I know I don't know anything (Socrates)
* Kindly Mark and Vote this reply if it helps please, as it will be beneficial to more Community members reading here