【问题标题】:How do delete all checkboxes in a range of cells如何删除一系列单元格中的所有复选框
【发布时间】:2013-03-20 04:48:12
【问题描述】:

我有代码可以删除某个单元格中的复选框,但我需要它来删除我选择的范围内的所有复选框。以下是我删除某个单元格中的复选框的代码。

Columns("B:B").Select
Selection.Find(What:="FIELD SERVICES", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(1, -1).Select
Dim CB8 As CheckBox
For Each CB8 In ActiveSheet.CheckBoxes
    If CB8.TopLeftCell.Address = ActiveCell.Address Then CB8.Delete
    Next

以下是我如何尝试更改它以删除我需要的范围内的单元格,但它只删除该范围的第一个单元格中的复选框。

Columns("B:B").Select
Selection.Find(What:="FIELD SERVICES", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
Range(ActiveCell.Offset(1, -1), ActiveCell.Offset(8, 0).Select
Dim CB8 As CheckBox
For Each CB8 In ActiveSheet.CheckBoxes
    If CB8.TopLeftCell.Address = ActiveCell.Address Then CB8.Delete
    Next

非常感谢任何建议。

【问题讨论】:

    标签: excel vba


    【解决方案1】:
    Dim f as Range, cbRange as range
    Dim CB8 As CheckBox
    
    
    Set f = Columns("B:B").Find(What:="FIELD SERVICES", After:=ActiveCell, _
                                LookIn:=xlFormulas, LookAt:=xlPart)
    
    if not f is Nothing then
       set cbRange = f.parent.range(f.Offset(1, -1), f.Offset(8, 0))
       For Each CB8 In ActiveSheet.CheckBoxes
         If not application.intersect(CB8.TopLeftCell, cbRange) is nothing Then CB8.Delete
       Next
    end if
    

    【讨论】:

      猜你喜欢
      • 2021-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-19
      • 2020-02-28
      • 1970-01-01
      • 1970-01-01
      • 2018-01-04
      相关资源
      最近更新 更多