![](/img/trans.png)
[英]Excel VBA delete row if cell value not found in a column in other sheet
[英]How to locate a cell value that ends in “net” and delete row in Excel VBA
我有这个程序正在寻找Col D中的任何单元格,其中值以“net”结尾,然后它将删除整个行/行。 但它不会删除值以“net”结尾的所有行。 我没有想法。
Sub DeleteRows_net()
Application.ScreenUpdating = False
Dim rng As Range
For Each rng In Range("D4:D2700")
If InStr(1, rng.Value, "net") > 0 Then
rng.EntireRow.Delete
End If
Next rng
End Sub
这是如此常见的错误......当你循环删除时,你必须从最后一个元素开始向第一个方向开始。 将循环更改为:
Dim i%
For i=2700 to 4 Step -1
If InStr(1, Cells(i, "D").Value, "net") > 0 Then
Cells(i, "D").EntireRow.Delete
End If
Next i
顺便说一下......不要忘记在Application.ScreenUpdating = True
结束前的某个地方放置Application.ScreenUpdating = True
!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.