在Excel中检查框

我试图插入多个checkbox(100 +),但不希望单独添加它们。 有没有这样做的快捷方式? 我已经尝试了拉下的方法,它确实做了更多,但是他们都连接起来 – 复制和粘贴同样发生! 当点击1时,他们都是!

单击checkbox时触发的macros如下,不知是否可以修改?

Sub tick() Dim ws As Worksheet Dim chk As CheckBox Dim lColD As Long Dim lColChk As Long Dim lRow As Long Dim rngD As Range lColD = 3 'number of columns to the right for date Set ws = ActiveSheet Set chk = ws.CheckBoxes(Application.Caller) lRow = chk.TopLeftCell.Row lColChk = chk.TopLeftCell.Column Set rngD = ws.Cells(lRow, lColChk + lColD) Select Case chk.Value Case 1 'box is checked rngD.Value = Date Case Else 'box is not checked rngD.ClearContents End Select End Sub 

这是我经常使用的代码。 如果您select一个范围并运行这个macros – 它会为每个选中的单元格添加一个checkbox,并将其与该单元格的值绑定(布尔值)

我不使用字幕 – 但是如果你愿意的话,你可以很容易地修改它。

我希望这个对你有用

 Sub Add_checkboxes() Application.ScreenUpdating = False For Each the_cell In Selection ActiveSheet.CheckBoxes.Add(Range(the_cell.Address).Left, Range(the_cell.Address).top, 18, 12).Select With Selection .Caption = "" .Value = xlOff ' .LinkedCell = the_cell.Address .Display3DShading = False End With Next Application.ScreenUpdating = True End Sub 

将此代码添加到VBA中的Sheet-Module中,并用“select”标记要用作checkbox的列(仅举例)。 此过程在双击时用“X”标记指定的单元格

 Private Sub Worksheet_beforedoubleClick(ByVal Target As Range, Cancel As Boolean) 'If row 6 of a cell contains "Selection" all rows below are used as checkboxes. If Me.Cells(6, Target.Column) = "Selection" And Target.Row > 6 Then 'Function to mark the field with an "x" If Target.Value = "x" Then Target.Value = "" Else Target.Value = "x" End If End If End Sub