Deleting rows with values based on a column

前端 未结 3 1697
独厮守ぢ
独厮守ぢ 2020-12-22 04:05

I have a monthly base with almost 373,000 lines. Of these, part has a low value or is blank. I\'d like to erase this lines.

I have part of this code to delete those

3条回答
  •  粉色の甜心
    2020-12-22 05:05

    How about:

    Sub ZeroKiller()
        Dim N As Long, ToBeKilled As Range
        Dim i As Long
    
        N = Cells(Rows.Count, "A").End(xlUp).Row
        For i = 1 To N
            If Cells(i, "D").Value = 0 Or Cells(i, "D").Value = "" Then
                If ToBeKilled Is Nothing Then
                    Set ToBeKilled = Cells(i, "D")
                Else
                    Set ToBeKilled = Union(ToBeKilled, Cells(i, "D"))
                End If
            End If
        Next i
    
        If Not ToBeKilled Is Nothing Then
            ToBeKilled.EntireRow.Delete
        End If
    End Sub
    

    This assumes that A is the longest column. If this is not always the case, use:

    N = Range("A1").CurrentRegion.Rows.Count
    

提交回复
热议问题