用于将复选框插入每个单元格并将其分配给Excel中的该单元格并在特定选定单元格中返回true false的脚本

时间:2015-02-17 03:54:19

标签: excel vba excel-vba checkbox

我需要这个公式的额外帮助。在我的excel工作表中输入此脚本后,真正的false将返回到复选框的同一单元格(下一个)。如何修改脚本,以便为一个复选框返回true false,例如在单元格(AI9)和" AI10,NEXT AI11等中的以下复选框。

Sub AddCheckBoxes()

Dim cb As CheckBox
Dim myRange As Range, cel As Range
Dim wks As Worksheet

Set wks = Sheets("mySheet") 'adjust sheet to your needs

Set myRange = wks.Range("A1:A10") ' adjust range to your needs

For Each cel In myRange

    Set cb = wks.CheckBoxes.Add(cel.Left, cel.Top, 30, 6) 'you can adjust left, top, height, width to your needs


    With cb

        .Caption = ""
        .LinkedCell = cel.Address

    End With

Next

End Sub

1 个答案:

答案 0 :(得分:0)

.LinkedCell = wks.Cells(cel.Row,"AI").Address()