我使用以下脚本将复选框添加到一系列单元格中。我想通过检查单元格是否已经包含一个复选框来增强此功能,如果它确实没有在单元格中添加新的复选框,即只有复选框添加到该范围内的单元格(如果它尚未包含复选框)
LRow = ActiveSheet.Range("D" & Rows.Count).End(xlUp).Row
For cell = 10 To LRow
CLeft = Cells(cell, "R").Left
CTop = Cells(cell, "R").Top
CHeight = Cells(cell, "R").Height
CWidth = Cells(cell, "R").Width
ActiveSheet.CheckBoxes.Add(CLeft, CTop, CWidth, CHeight).Select
With Selection
.Caption = ""
.Value = xlOff
.Display3DShading = False
End With
Next cell
答案 0 :(得分:1)
使用此功能检查范围是否包含复选框:
Public Function HasCheckbox(rng As Range) As Boolean
For Each CB In ActiveSheet.CheckBoxes
If Not Application.Intersect(rng, CB.TopLeftCell) Is Nothing Then
HasCheckbox = True
Exit Function
End If
Next CB
HasCheckbox = False
End Function