使用VBA删除#REF的每一行

时间:2015-05-25 18:16:36

标签: excel vba excel-vba

我想删除A列中包含#REF的每一行。

我的代码仅适用于value,不适用于#REF

Dim varFindThis As Variant
Dim rngLookIn As Range
Dim f As String

varFindThis = Worksheets("Suivi2").Range("B1")

Set rngLookIn = Worksheets("Suivi2").Range("A:A")

If Not rngLookIn.Find(varFindThis, LookIn:=xlValues) Is Nothing Then  

    f = Worksheets("Suivi2").Range("B1").Value

'Since i didn't got that clear, here above you must create a code to declare "f" as whatever you want

    Set c = Worksheets("Suivi2").Range("A:A").Find(f)
      Worksheets("Suivi2").Range(c.Address).EntireRow.Delete

End If

1 个答案:

答案 0 :(得分:0)

您可以使用Range.SpecialCells method快速找到Worksheet.UsedRange property中的所有错误。

on error resume next
with Worksheets("Suivi2").Columns(1)
    if not .specialcells(xlCellTypeFormulas, xlErrors) is nothing then _
        .specialcells(xlCellTypeFormulas, xlErrors).EntireRow.Delete
end with
on error goto 0