简体   繁体   English

如果行中的一个单元格包含错误,如何删除整行?

[英]How do I delete an entire row if a cell in the row contains an error?

On Error Resume Next
Columns("C").SpecialCells(xlFormulas, xlErrors).EntireRow.Delete
On Error GoTo 0

Range("A6").Select

This is what I have. 这就是我所拥有的。 I was working fine. 我工作很好

The problem is when the columns C does not have errors, it keeps showing an error message saying it can't fine the error type. 问题是,当列C没有错误时,它会继续显示一条错误消息,指出无法对错误类型进行优化。

It works fine when there are errors. 出现错误时,它可以正常工作。

Does anyone know how to fix this? 有谁知道如何解决这一问题? Maybe an if statement? 也许是if语句?

Thanks guys 多谢你们

This seems to work: 这似乎可行:

Sub marine()
    Dim r As Range
    On Error Resume Next
    Set r = Range("C:C").Cells.SpecialCells(xlCellTypeFormulas, xlErrors)
    On Error GoTo 0
    If Not r Is Nothing Then
        r.EntireRow.Delete
    End If
End Sub

If it does not work and you still see an error message, then error handling must be enabled. 如果它不起作用,并且您仍然看到错误消息,则必须启用错误处理。 From the VBE window menu: 从VBE窗口菜单:

Tools > Options... > General > and make sure Break on Unhandled Errors is checked. 工具 > 选项... > 常规 >,并确保选中了“未处理的错误中断”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM