首页 > 解决方案 > 如果单元格 ("D(j):H(j)") 只有值 0,则删除行

问题描述

有人可以帮我吗?在 C 列中,单个单元格最初是空的,并且代码在该部分中有效。在 C 列中有几个空单元格的部分中,代码不起作用。关于“lastrow2”或代码的其他位置,我究竟需要改变什么才能达到预期的目标?

lastrow2 = Cells(Cells.Rows.Count, "C").End(xlUp).Row

For j = lastrow2 To 1 Step -1
    If (Cells(j, 4) = 0 And Cells(j, 5) = 0 And Cells(j, 6) = 0 And Cells(j, 7) = 0 And Cells(j, 8) = 0 And Cells(j, 9) = 0) Then
        Rows(j).Delete
    End If
Next j

非常感谢您的支持。:)

最好的问候, 巴马内

标签: excelvba

解决方案


测试列C可能太浅。这个:

Sub trewq()
    ActiveSheet.UsedRange
    Set r = ActiveSheet.UsedRange

    lastrow2 = r.Rows.Count + r.Row - 1

    For j = lastrow2 To 1 Step -1
        If (Cells(j, 4) = 0 And Cells(j, 5) = 0 And Cells(j, 6) = 0 And Cells(j, 7) = 0 And Cells(j, 8) = 0 And Cells(j, 9) = 0) Then
            Rows(j).Delete
        End If
    Next j
End Sub

可能会更好......我们正在检查DI列


推荐阅读