我正在使用以下脚本将复选框添加到一系列单元格。我想通过检查单元格是否已经包含一个复选框来增强这一点,如果它包含,那么不要在单元格中添加一个新的复选框,即如果它还没有包含一个复选框,则只在该范围内的单元格中添加一个复选框.
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
最佳答案
使用此函数检查范围是否包含复选框:
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
关于Excel VBA - 检查单元格是否包含复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35921758/