4

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, probably 5 or so total. I can use macros to get to the specific cells these unneeded check boxes. These unneeded check boxes will not always be in the same place due to my data changing so I will have to delete them one at a time which shouldn't be a problem other than I don't know the code to delete a check box from the active cell. I need a code to delete check box from active cell or selected cell. I have included some of my coding I have tried below. The first section is just getting me to the correct cell to delete the check box out of. The second part are two different codes I have tried to delete the check box but neither worked. I appreciate your input.

'To delete unwanted checkboxes
    Sheets("Quote Sheet").Select
    Range("B9").Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(0, -1).Select

    ActiveSheet.Shapes.Range(Array("Check Box 456")).Select
    Selection.Delete
    Selection.Cut

    ActiveCell.CheckBoxes.Delete
    Selection.FormatConditions.Delete
4

1 回答 1

9

此代码将删除位于活动单元格的任何 Excel 复选框。

Sub DeleteCheckbox()
    Dim cb As CheckBox

    For Each cb In ActiveSheet.CheckBoxes
        If cb.TopLeftCell.Address = ActiveCell.Address Then cb.Delete
    Next
End Sub

如果您使用 ActiveX 复选框,此代码将完成这项工作:

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
于 2013-02-19T19:21:20.590 回答