如果列值为#N / V,则删除行

时间:2015-08-24 13:33:29

标签: excel vba

我只是想知道是否有人可以帮助我获得细胞的价值。 如果A列中单元格的值为ProcessBuilder pb = new ProcessBuilder("<bashname>", "<scriptpath>"); Process p = pb.start(); OutputStream ops = p.getOutputStream(); ,我试图删除整行。我几乎尝试了一切。这是我的代码:

#N/V

2 个答案:

答案 0 :(得分:1)

For Each ws In Sheets(Array("List"))
        lastRow = ws.Range("A" & Rows.Count).End(xlUp).row
        For i = 1 To lastRow
          If ws.Cells(i, 1).Text = "#N/V" Then
             ws.Cells(i,1).entirerow.Delete
             i = i - 1
          End If
        Next i
Next

对@ Grade'Eh'Bacon的建议:

For Each ws In Sheets(Array("List"))
        lastRow = ws.Range("A" & Rows.Count).End(xlUp).row
        For i = lastrow To 1 step -1
          If ws.Cells(i, 1).Text = "#N/V" Then
             ws.Cells(i,1).entirerow.Delete

          End If
        Next i
Next

使用Autofilterfunction:

Dim lastRow As Long
lastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row

With Range("A1:A1")
    .select
    If ActiveSheet.AutoFilterMode Then
      .AutoFilter field:=1, Criteria1:="#N/V"
      .Range("A1:A" & lastRow).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    End If
End With

答案 1 :(得分:1)

如果您想要删除A列中所有类型错误的行,您可以使用SpecialCells方法在单个语句中查找和删除它们:

Range("A:A").SpecialCells(xlCellTypeFormulas, xlErrors).EntireRow.Delete