0

有人知道这段代码有什么问题吗?当 A 到 F 列为空时,它应该删除行。谢谢

Sub range_reporter()
    Dim n As Long
    Dim nLastRow As Long
    Dim nFirstRow As Long
    ActiveSheet.UsedRange
    Set r = ActiveSheet.UsedRange
    nLastRow = r.Rows.Count + r.Row - 1
    nFirstRow = r.Row
    For n = nLastRow To nFirstRow Step -1
        If Cells(n, "A") & Cells(n, "B") & Cells(n, "C") & Cells(n, "D") & Cells(n, "E") & Cells(n, "F") = "" Then
            Cells(n, "A").EntireRow.Delete
        End If
    Next n
End Sub 
4

1 回答 1

0

您的问题是您对“AND”使用了不正确的语法(“&”字符用于连接)。看看下面的代码,我刚刚测试过,它工作正常。

Sub range_reporter()
    Dim n As Long
    Dim nLastRow As Long
    Dim nFirstRow As Long

    ActiveSheet.UsedRange

    Set r = ActiveSheet.UsedRange
    nLastRow = r.Rows.Count + r.Row - 1
    nFirstRow = r.Row

    For n = nLastRow To nFirstRow Step -1
        If Cells(n, "A") = "" And Cells(n, "B") = "" And Cells(n, "C") = "" And Cells(n, "D") = "" And Cells(n, "E") = "" And Cells(n, "F") = "" Then
            Cells(n, "A").EntireRow.Delete
        End If
    Next n

End Sub
于 2013-10-27T20:28:12.337 回答