mardi 14 juillet 2015

How to add two named checkboxes to one cell

I've looked around but can't figure out how to add two checkboxes to a single cell. Do I need to use OLEObjects.Add or not? I need to add two columns of checkboxes in column E. Thanks in advance.

Here is my attempt:

LRow = ActiveSheet.Range("G" & Rows.count).End(xlUp).Row

For cell = 2 To LRow

    If Cells(cell, "G").Value <> "" Then

        CLeft = Cells(cell, "E").Left

        CTop = Cells(cell, "E").Top

        CHeight = Cells(cell, "E").Height / 2

        CWidth = Cells(cell, "E").Width


        ActiveSheet.CheckBoxes.Add(CLeft, CTop, CWidth, CHeight).Select

        With Selection
            .Caption = ""
            .name = "cbSet1_" & cell
            .Value = xlOff
            .LinkedCell = "E" & cell
            .Display3DShading = False

        End With
    End If
Next cell

For cellF = 2 To LRow

    If Cells(cellF, "G").Value <> "" Then

        CLeftF = Cells(cellF, "E").Left

        CTopF = Cells(cellF, "E").Top

        CHeightF = Cells(cellF, "E").Height

        CWidthF = Cells(cellF, "E").Width


        ActiveSheet.CheckBoxes.Add(CLeftF, CTopF, CWidthF, CHeightF).Select

        With Selection
            .Caption = ""
            .name = "cbSet2_" & cell
            .Value = xlOff
            .Display3DShading = False
        End With
    End If
Next cellF




Aucun commentaire:

Enregistrer un commentaire