Share via

creating multiple checkboxes in a spreadsheet

Anonymous
2012-09-18T03:33:52+00:00

I have a worksheet in Excel 2010.  In Column A are names of students.  In Column B is a checkbox (TRUE/FALSE).  In Column C is a checkbox (TRUE/FALSE).  I have over 50 students and I want to be able to create a checkbox in each column without having to create the checkbox one at a time. Is there a way to create multiple checkboxes in Excel?  I have tried copy and paste but the formula is reading the same exact reference that is in the first checkbox created.  I have tried to fill-in by dragging the contents of the cell down and over but again, it reads the same reference from the first checkbox.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
Answer accepted by question author
  1. Anonymous
    2012-09-18T10:11:23+00:00

    Hello

    Sheello some things where missing, i added them. Also i created a macro to erase checkboxes (if one cell is selected then erases all checkboxes within sheet, otherwise it tries to erase only within selection boundaries...)

    Now the creator Sub will:

    • Create Checkboxes
    • Resize columns/Rows if to small (can be ommitted, read comments inside)
    • Link to cell
    • Specify Checkbox Column (will fit inside) / Row (same)
    • Specify Starting Row and Ending Row

    what else could anyone want????

    :D give it a try and tell me what you think of it.

    I Thank again Sheeloo for the ActiveSheet.OLEObjects.Add(ClassType:="Forms.CheckBox.1", Link:=False, _DisplayAsIcon:=False, Left:=dblLeft, Top:=dblTop, Width:=dblWidth, Height:= _  dblHeight).Select code, couldn't (wouldn't) have done it without it.

    Copy paste code below or download from here

    '------------CODE START HERE-----------

    ' Create and Link many Checkboxes

    '

    Sub CheckBoxCreator()

    Dim dblTop As Double, dblLeft As Double, dblWidth As Double, dblHeight As Double

    Dim Irw As Long, ChBoxClmn As Long, LinkClmn As Long, I As Long, Qnty As Long

    Irw = 5 ' Row to start from

    ChBoxClmn = Range("d1").Column ' Where (column) to place the CheckBox

    LinkClmn = ChBoxClmn - 1 ' Where (column) to make the link

    Iend = 10 ' Row to Stop

    If Columns(ChBoxClmn).ColumnWidth < 20 Then Columns(ChBoxClmn).ColumnWidth = 20 'Suggested Width fix

    For I = Irw To Iend

    If Rows(I).RowHeight < 20 Then Rows(I).RowHeight = 20 ' Suggested Height fix

    With Cells(I, 4)

    dblTop = .Top: dblLeft = .Left: dblWidth = .Width: dblHeight = .Height

    End With

    ActiveSheet.OLEObjects.Add(ClassType:="Forms.CheckBox.1", Link:=False, _

    DisplayAsIcon:=False, Left:=dblLeft, Top:=dblTop, Width:=dblWidth, Height:= _

    dblHeight).Select

    Selection.LinkedCell = Cells(I, LinkClmn).Address(False, True)

    Next

    End Sub

    ' Erase all checkboxes in sheet (single cell selected) or all checkboxes

    ' within selected region

    '

    Sub CheckboxEraser()

    Dim dblTop As Double, dblLeft As Double, dblWidth As Double, dblHeight As Double

    Dim A

    If Selection.Cells.Count = 1 Then

    For Each A In ActiveSheet.Shapes

    If InStr(LCase(A.Name), "checkbox") > 0 Then A.Delete

    Next

    Else

    With Selection

    dblTop = .Top: dblLeft = .Left: dblWidth = .Width: dblHeight = .Height

    End With

    For Each A In ActiveSheet.Shapes

    If InStr(LCase(A.Name), "checkbox") > 0 Then

    If A.Top >= dblTop And A.Top < dblTop + dblHeight And A.Left > dblLeft And A.Left < dblLeft + dblWidth Then

    A.Delete

    End If

    End If

    Next

    End If

    End Sub

    '---------CODE END HERE------------

    2 people found this answer helpful.
    0 comments No comments
Answer accepted by question author
  1. Anonymous
    2012-09-18T07:34:29+00:00

    You may try a macro like the one below;

    Sub insertCheckBoxes()

    '

    ' insertCheckBoxes Macro

    '

    Dim dblTop, dblLeft, dblWidth, dblHeight As Double

    Dim i As Long

    dblTop = 30

    dblLeft = 150

    dblWidth = 32

    dblHeight = 32

    For i = 1 To 10

    dblTop = dblTop + 20

    ActiveSheet.OLEObjects.Add(ClassType:="Forms.CheckBox.1", Link:=False, _

        DisplayAsIcon:=False, Left:=dblLeft, Top:=dblTop, Width:=dblWidth, Height:= _

        dblHeight).Select

    Next

    End Sub

    1 person found this answer helpful.
    0 comments No comments
Answer accepted by question author
  1. Anonymous
    2012-09-23T06:24:48+00:00

    Hi

    Would Data Validation not be easier ?

    Regards

    JY

    0 comments No comments

10 additional answers

Sort by: Most helpful
  1. Anonymous
    2012-09-18T19:32:28+00:00

    Hello

    I believe code is very straigh-forward and simple, so tweaking anything will be easy. Since shapes are generally tough to handle it will be nice to have some functions/ tools for the job.

    Noonie, does it work for you to?

    0 comments No comments
  2. Anonymous
    2012-09-18T11:11:41+00:00

    Thanks Apostolos55 especially for the deletion code...

    what else could anyone want????

    I guess

    Captions of the checkboxes to be read from a given column...

    Option to leave n number of rows between checkboxes...

    Forecolor, Backcolor...

    I am just kidding :-)

    0 comments No comments