Forum Discussion
VBA/Macro Code for checkboxes
- Aug 18, 2021
You may simply try this...
Sub SetLinkedCells() Dim cb As CheckBox For Each cb In ActiveSheet.CheckBoxes cb.LinkedCell = cb.TopLeftCell.Address Next cb End Sub
You may simply try this...
Sub SetLinkedCells()
Dim cb As CheckBox
For Each cb In ActiveSheet.CheckBoxes
cb.LinkedCell = cb.TopLeftCell.Address
Next cb
End Sub
- craboakAug 18, 2021Copper Contributor
Subodh_Tiwari_sktneer
I like that this doesn't require me to directly select the boxes. Issue I am running into with this one is it is tying it to the cell above. Example: Checkbox in Cell B4 is hooked to cell B3 rather than B4.
Is there a way to adjust for that? If so this will be perfect!- Subodh_Tiwari_sktneerAug 18, 2021Silver Contributor
That means the CheckBoxes are not inside the cell boundaries. If a CheckBox is properly inserted inside a cell, the TopLeftCell property of the CheckBox will refer to the cell it is sitting in.
In your case, you may just change the line within the For Loop to this...
cb.LinkedCell = cb.TopLeftCell.Offset(1).Address
If that takes care of your original question, please take a minute to accept the post with the proposed solution as a Best Response to mark your question as Solved.
- craboakAug 18, 2021Copper ContributorAh perfect. I fixed the alignment of the boxes and your original solution worked. Thank you so much.