我设计了一些代码来帮助删除引用错误,但是在我将宏分配给按钮之前它不会自动删除。我不希望这样,因为当我想将程序呈现给我的团队成员并且不得不用按钮在现场删除错误时,这似乎是不愉快的。我想把我的删除单元代码组合在一起并删除引用单元代码,以便它们可以同时运行但无济于事。是否可以将这两个代码组合起来实现我的目标,还是有任何解决方案或编码可以自动删除/隐藏参考错误?这是两个代码。非常感谢您的所有帮助!
Sub deletetry2()
Dim R As Range
Set rng = Nothing
On Error Resume Next
Set R = Application.InputBox("Select cells To be deleted", Type:=8)
If TypeName(R) <> "Range" Then
Exit Sub
Else
R.Delete
End If
End Sub
Sub Check_ReferenceDeletecolumn()
Dim rng As Range
Dim rngError As Range
Set rng = Sheets("Sheet3").Range("A1:G100")
On Error Resume Next
Set rngError = rng.Cells.SpecialCells(xlCellTypeFormulas, xlErrors)
On Error GoTo 0
If Not rngError Is Nothing Then
rngError.EntireColumn.Delete
'delete means cells will move up after deleting that entire row
End If
End Sub
答案 0 :(得分:0)
如果目标是从用户定义的范围中删除包含错误的所有行,则应该起作用:
Option Explicit
Public Sub cleanUserDefinedRange()
Dim response As Range
On Error Resume Next
Set response = Application.InputBox("Select range to clean up errors", Type:=8)
If Not response Is Nothing Then cleanUpErrors response
On Error GoTo 0
End Sub
'------------------------------------------------------------------------------------------
Private Sub cleanUpErrors(ByRef rng As Range)
Application.ScreenUpdating = False
rng.SpecialCells(xlCellTypeFormulas, xlErrors).EntireRow.Delete
Application.ScreenUpdating = True
End Sub