Fill range with linked checkboxes

viggenboy

New Member
Joined
Aug 19, 2011
Messages
2
I'm sure in an ancient version of Excel you could simply format a cell as true/false and it put in a checkbox (:confused:) anyhow here I am in Excel 2010 and wanting to put lots of linked check boxes on worksheets.

So I created a macro that puts a linked checkbox in the selected cell- no problem. Now I'd like to fill the whole of selected range (column) with linked checkboxes. So I created this VBA macro:

Sub AddCheckInSel()

Dim Locn, x, y, z

Locn = ActiveCell.Address

x = Range(Locn).Left
y = Range(Locn).Top
z = Range(Locn).Height

For Each cell In Selection

ActiveSheet.CheckBoxes.Add(x, y, 72, z).Select
Selection.Characters.Text = ""
With Selection
.Value = xlOff
.LinkedCell = Locn
.Display3DShading = False
End With

y = y + z


Next cell

End Sub

Select a range, run the macro and I looks great. BUT all of the checkboxes are linked to the top cell (DOH!) ... so what am I doing wrong.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
try adding this

Code:
For Each Cell In Selection
Cell.Activate
Locn = ActiveCell.Address
ActiveSheet.CheckBoxes.Add(x, y, 72, z).Select
Selection.Characters.Text = ""
With Selection
    .Value = xlOff
    .LinkedCell = Locn
    .Display3DShading = False
End With
 
Upvote 0
<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> AddCheckInSel()<br>    <br>    <SPAN style="color:#00007F">Dim</SPAN> cell <SPAN style="color:#00007F">As</SPAN> Range<br><br>    <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> cell <SPAN style="color:#00007F">In</SPAN> Selection<br>        <SPAN style="color:#00007F">With</SPAN> ActiveSheet.CheckBoxes.Add(cell.Left, cell.Top, 72, cell.Height)<br>            .Characters.Text = ""<br>            .Value = xlOff<br>            .LinkedCell = cell.Address<br>            .Display3DShading = <SPAN style="color:#00007F">False</SPAN><br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <SPAN style="color:#00007F">Next</SPAN> cell<br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
Thanks that's excellent.... wouldn't you think this was a common enough thing people wanted to do that it would be a built in function!
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,866
Members
452,948
Latest member
UsmanAli786

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