/ / Jak usunąć wszystkie pola wyboru w zakresie komórek - excel, excel-vba, vba

Jak usunąć wszystkie pola wyboru w zakresie komórek - excel, excel-vba, vba

Mam kod do usunięcia pola wyboru w pewnej komórce, ale potrzebuję go, aby usunąć wszystkie pola wyboru w zaznaczonym przeze mnie zakresie. Poniżej znajduje się kod, który mam, który usuwa pole wyboru w pewnej komórce.

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

Oto jak próbowałem to zmienić, aby usunąć komórki w zakresie, który potrzebuję, ale to tylko usuwa pole wyboru w pierwszej komórce zakresu.

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

Wszelkie porady są mile widziane.

Odpowiedzi:

2 dla odpowiedzi № 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