macros不删除所有符合要求的项目

我写了这个非常简单的macros来删除所有行,当列P有一个“1”或“0”和列L包含“假”。 无论如何,它似乎并没有连续运行。 我不得不反复运行macros来删除一切。

Sub Delete_rows() Dim Pcell As Range Dim LastPCell As Long Range("P2", Range("P65000").End(xlUp)).Name = "LastPCell" For Each Pcell In Range("LastPCell") If Pcell <= 1 And Pcell.Offset(0, -4) = "False" Then Pcell.Offset(0, 4).EntireRow.Delete Next Pcell End Sub 

只有大约10,000行,所以范围大小应该罚款。

在这一点上,我很尴尬,我没有能够麻烦拍摄它。 有任何想法吗?

谢谢。

在@ bernie的答案上展开

 Sub Delete_rows() Dim lastCell As Long, i As Integer, Pcell As Range lastCell = ActiveSheet.Range("P65000").End(xlUp).Row For i = lastCell To 2 Step -1 Set Pcell = ActiveSheet.Cells(i, 16) If Pcell <= 1 And Pcell.Offset(0, -4) = "False" Then Pcell.Offset(0, 4).EntireRow.Delete End If Next i End Sub