根据所选单元格删除多个复选框

时间:2015-01-28 23:44:48

标签: excel vba excel-vba

我有一些Excel工作表,它们使用ActiveX复选框来控制某些活动。我正在寻找一种方法来删除所选单元格的列(文本和复选框)的内容。到目前为止,我一直在使用下面的代码,但它只删除了活动单元格下方单元格中的复选框。任何帮助将不胜感激!

Sub DeleteJob1_Click()

If MsgBox("This will erase this job! Are you sure?", vbYesNo) = vbNo Then Exit Sub
Columns(ActiveCell.Column).Delete

Dim cb As CheckBox

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

End Sub

1 个答案:

答案 0 :(得分:0)

尝试:

Sub DeleteJob1_Click()
    Dim cb As CheckBox
    If MsgBox("This will erase this job! Are you sure?", vbYesNo) = vbNo Then Exit Sub
    For Each cb In ActiveSheet.CheckBoxes
        If cb.TopLeftCell.Column = ActiveCell.Column Then cb.Delete
    Next
    Columns(ActiveCell.Column).Delete
End Sub