1

我写了这个非常简单的宏来删除当 P 列有“1”或“0”并且 L 列包含“假”时的所有行。无论出于何种原因,它似乎都没有连续运行。我必须一遍又一遍地重复运行宏来删除所有内容。

    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 行,所以范围大小应该没问题。

在这一点上我有点傻眼,我一直无法解决它。有任何想法吗?

谢谢。

4

1 回答 1

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
于 2012-06-22T23:43:38.073 回答