FunsizedNerd
New Member
- Joined
- Mar 20, 2019
- Messages
- 17
I am trying to set up a macro that will search the range of cells for any checkboxes, and if there are any in the range, they will be deleted (and then I add new ones in the next step).
However, when I run the macro, it deletes ALL checkboxes in the sheet, rather than just those that are within the selected range. How can I change the If statement and Intersect condition to work properly?
Dim c As Range, myRange As Range
Dim check As CheckBox
'OD Checkboxes
Range("F2", Range("F2").End(xlDown)).Select
Selection.Offset(0, -1).Select
Set myRange = Selection
For Each check In Sheets("Summary").CheckBoxes
If Not Intersect(check.TopLeftCell, Range("myRange")) Is Nothing Then
check.Delete
End If
Next
However, when I run the macro, it deletes ALL checkboxes in the sheet, rather than just those that are within the selected range. How can I change the If statement and Intersect condition to work properly?
Dim c As Range, myRange As Range
Dim check As CheckBox
'OD Checkboxes
Range("F2", Range("F2").End(xlDown)).Select
Selection.Offset(0, -1).Select
Set myRange = Selection
For Each check In Sheets("Summary").CheckBoxes
If Not Intersect(check.TopLeftCell, Range("myRange")) Is Nothing Then
check.Delete
End If
Next