我写了这个非常简单的宏来删除所有行,当列P有“1”或“0”而列L包含“False”时。出于任何原因,它似乎不会连续运行。我必须反复运行宏来删除所有内容。
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行,所以范围大小应该没问题。
此时我有点傻眼,我无法解决问题。有任何想法吗?
感谢。
答案 0 :(得分:3)
扩展@ 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