根据条件删除指定的行
下面是根据D列删除等如0值的行,
Set MyRange = Columns("d")
On Error GoTo 0
MatchString = 0
Set C = MyRange.Find(What:=MatchString, After:=MyRange.Cells(1), LookIn:=xlValues, Lookat:=xlWhole)
If Not C Is Nothing Then
Set DelRange = C
FirstAddress = C.Address
Do
Set C = MyRange.FindNext(C)
Set DelRange = Union(DelRange, C)
Loop While FirstAddress <> C.Address
End If
If Not DelRange Is Nothing Then DelRange.EntireRow.Delete
-------------------
但是我要根据两个条件,A列的值和D列等如0值的行
下面的代码:
for r = 2 to 20
if range("a"&r) = "a列的条件值" and range("d"&r) = 0 then
row(r).delete
next r
这段代码不能删除所有符合条件的行
只能跳一行删除,不知为什么?
请高师指点