从某个单元格删除一个复选框的宏 [英] Macro to delete a checkbox from a certain cell

查看:131
本文介绍了从某个单元格删除一个复选框的宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将复选框拉入电子表格,用于选择某些订单项以获得最终费用。有一些不需要的复选框被拉入,总共可能是5左右。我可以使用宏来访问特定的单元格这些不需要的复选框。由于我的数据更改,这些不需要的复选框不会总是在同一个地方,所以我必须一次删除它们,不应该是一个问题,而不是我不知道删除复选框的代码活性细胞。我需要一个代码删除复选框从活动单元格或所选单元格。我已经包括我在下面尝试过的一些编码。第一部分只是让我到正确的单元格删除复选框。第二部分是两个不同的代码,我试图删除复选框,但没有工作。感谢您的输入。

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


推荐答案

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

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

如果您使用ActiveX复选框,此代码将执行以下工作:

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

这篇关于从某个单元格删除一个复选框的宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆