user2457968
user2457968

Reputation: 109

macro to delete activex checkbox in the selected range

I am trying to delete the 'ActiveX' check box using below code. However, it is not working. Kindly advise.

Sub CheckboxRemove()
    Dim cl As Range
    Dim cb As Object

    For Each cl In Selection
        Set cb = ActiveSheet.CheckBoxes.Delete()
    Next cl

    Set cl = Nothing
    Set cb = Nothing
End Sub

For an example, I have placed these ActiveX check boxes from A1 to F1 cell range. I will select the cells from A1:F1 and when I run this macro then these checkboxes should be deleted. Please advise

Upvotes: 1

Views: 3372

Answers (1)

Gary's Student
Gary's Student

Reputation: 96753

Treat the checkboxes as Shapes and then check to the position of the upper left hand cell:

Sub CheckKiller()
Dim s As Shape
For Each s In ActiveSheet.Shapes
    If s.Type = 12 Then
        If Not Intersect(s.TopLeftCell, Selection) Is Nothing Then
            s.Delete
        End If
    End If
Next
End Sub

Upvotes: 0

Related Questions