如果列值是#N / V,则删除行
我只是想知道有没有人可以帮助我细胞的价值。 我试图删除整个行,如果列A中的单元格的值是#N/V
我试过几乎所有的东西 这是我的代码:
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).Delete End If Next i Next
如果您想摆脱A列中所有types错误的行,可以使用SpecialCells
方法在一个语句中查找和删除它们:
Range("A:A").SpecialCells(xlCellTypeFormulas, xlErrors).EntireRow.Delete
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
build议@ 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