我有一个电子表格,其中一列中有复选框,我希望有一个删除重复行的宏(带有这些行的复选框)。
我目前有以下代码,它完全符合我的需要,但是复选框不会删除行。我正在使用带有表单控件复选框的excel 2010,这些复选框设置为"移动但不要使用单元格"。
有人可以帮我添加一行代码,删除行时会删除该复选框。
这是我当前的宏:
Sub CleanSheet()
Dim LastRowcheck As Long, n1 As Long
Dim DelRange As Range
With Worksheets("Scale Costs")
LastRowcheck = .Range("A" & .Rows.Count).End(xlUp).Row
For n1 = 1 To LastRowcheck
If .Cells(n1, 1).Value = Cells(n1 + 1, 1).Value Then
If DelRange Is Nothing Then
Set DelRange = .Rows(n1)
Else
Set DelRange = Union(DelRange, .Rows(n1))
End If
End If
Next n1
If Not DelRange Is Nothing Then DelRange.Delete
End With
End Sub
我发现在线代码可以删除所选单元格中的复选框,但我不确定如何将其添加到我拥有的宏中。
答案 0 :(得分:0)
将该行放入删除代码
If Not DelRange Is Nothing Then
' delete checkbox here
DelRange.Delete
End If
答案 1 :(得分:0)
这应该可以解决问题。
Sub DeleteCheckboxFromRow(ws As Worksheet, r As Range)
Dim obj As OLEObject, ck As CheckBox
For Each obj In ws.OLEObjects
If TypeName(obj.Object) = "CheckBox" Then
If Not Intersect(obj.TopLeftCell, r.EntireRow) Is Nothing Then obj.Delete
End If
Next
For Each ck In ws.CheckBoxes
If Not Intersect(ck.TopLeftCell, r.EntireRow) Is Nothing Then ck.Delete
Next
End Sub