Macro to delete a checkbox from a certain cell

后端 未结 1 667
执笔经年
执笔经年 2021-01-19 04:00

I am pulling check boxes into a spreadsheet to be used to select certain line items to get a final cost. There are a few unneeded check boxes that get pulled in though, prob

相关标签:
1条回答
  • 2021-01-19 04:40

    This code will delete any Excel checkbox located at the active cell.

    Sub DeleteCheckbox()
        Dim cb As CheckBox
    
        For Each cb In ActiveSheet.CheckBoxes
            If cb.TopLeftCell.Address = ActiveCell.Address Then cb.Delete
        Next
    End Sub
    

    In case you're using ActiveX checkboxes, this code will do the job:

    Sub DeleteActiveXCheckbox()
        Dim obj As OLEObject
        Dim cb As MSForms.CheckBox
    
        For Each obj In ActiveSheet.OLEObjects
            If TypeOf obj.Object Is MSForms.CheckBox Then
                Set cb = obj.Object
                If cb.ShapeRange.Item(1).TopLeftCell.Address = _
                    ActiveCell.Address Then obj.Delete
            End If
        Next
    End Sub
    
    0 讨论(0)
提交回复
热议问题