2013-03-19 2 views
0

특정 셀의 확인란을 삭제하는 코드가 있지만 선택한 범위의 모든 확인란을 삭제해야합니다. 다음은 특정 셀에서 확인란을 삭제하는 코드입니다. 다음셀 범위의 모든 확인란을 삭제하는 방법

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 

모든 조언을 크게 듣습니다.

답변

2
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 
관련 문제