Forum Discussion
Inserting one checkbox and linking to multiple cells to trigger sums
Hi - I am adding checkboxes that are linked to cells to calculate costs. So far I have one check box per cell. I was wanting to link 1 checkbox to 6 cells so that I can check one box and select them all. Is this possible? I have not found it to work when trying to link the cell and selecting the range. Any advice?
Thanks so much!
21 Replies
- NikolinoDEGold Contributor
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)
- Jacqueline28Copper Contributor
Hi NikolinoDE - Could I send you and example of what I am working on to see if you could give me specific insights to the document?
Thanks in advance!
- NikolinoDEGold Contributor
Here are two files in this direction as an example.
I hope that you will take a step back into your project with these suggested solutions.
I wish you continued success with Excel
Nikolino
I know I don't know anything (Socrates)
* Kindly Mark and Vote any reply if it helps please, as it will be beneficial to more Community members reading here.
- NikolinoDEGold Contributor
- Jacqueline28Copper Contributor
Thank you so much for these insights. What is the 10 and 3 referencing in the formula?
Thanks!