Excel vba: Add checkboxes to a sheet (1/2)
In this post I will demonstrate how to create checkboxes in nonempty rows.
VBA code
Sub Addcheckboxes()
Dim cell, LRow As Single
Dim chkbx As CheckBox
Dim CLeft, CTop, CHeight, CWidth As Double
Application.ScreenUpdating = False
LRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For cell = 2 To LRow
If Cells(cell, "A").Value <> "" Then
CLeft = Cells(cell, "E").Left
CTop = Cells(cell, "E").Top
CHeight = Cells(cell, "E").Height
CWidth = Cells(cell, "E").Width
ActiveSheet.CheckBoxes.Add(CLeft, CTop, CWidth, CHeight).Select
With Selection
.Caption = ""
.Value = xlOff
.Display3DShading = False
End With
End If
Next cell
Application.ScreenUpdating = True
End Sub
Sub RemoveCheckboxes()
Dim chkbx As CheckBox
For Each chkbx In ActiveSheet.CheckBoxes
chkbx.Delete
Next
End SubWhere to copy vba code?
- Copy above code
- Press Alt+F11 in excel
- Insert a module
- Paste code into code window
- Return to excel
I have assigned the macros to two buttons: Add Checkboxes and Remove Checkboxes.
- Go to Developer tab
- Click "Insert Controls" button
- Click "Button" button

- Create the button on a sheet
- Select a macro
- Click OK!
In the next post I will describe how to copy selected rows to another sheet.
Download excel file
Add checkboxes to a sheet.xlsm
Next: Copy selected rows (checkboxes) (2/2)
Related posts:
Open excel files in a folder (vba)
Copy selected rows (checkboxes) (2/2)
Toggle a macro on/off using a button
Disable autofit column widths for all pivot tables in a sheet


















You can reduce your RemoveCheckboxes macro to a one-liner...
Sub RemoveCheckboxes()
ActiveSheet.CheckBoxes.Delete
End Sub
Rick Rothstein (MVP - Excel),
Thanks!!