如何删除一系列单元格中的所有复选框

如何删除一系列单元格中的所有复选框

本文介绍了如何删除一系列单元格中的所有复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有删除特定单元格中的复选框的代码,但是我需要它来删除所选范围内的所有复选框.以下是我删除特定单元格中的复选框的代码.

I have code to delete a checkbox in a certain cell but I need it to delete all checkboxes in a range I have selected. Following is the code I have that deletes a checkbox in a certain cell.

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

以下是我尝试对其进行更改以删除所需范围内的单元格的方法,但是它仅删除了该范围内第一个单元格中的复选框.

Following is how I tried to alter it to delete cells in the range I need but it only deletes the checkbox in the first cell of the range.

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

任何建议都将不胜感激.

Any advice is greatly appreciated.

推荐答案

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

这篇关于如何删除一系列单元格中的所有复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 23:54