Deleting rows with values based on a column

前端 未结 3 1710
独厮守ぢ
独厮守ぢ 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 04:55

    I am concerned about the 375K lines, who knows how long this will take to run.

        Sub Button1_Click()
    
        Dim i As Long
        For i = Cells(Rows.Count, "D").End(xlUp).Row To 2 Step -1
            If Cells(i, "D") = 0 Or Cells(i, "D") = "" Then
                Rows(i).Delete
            End If
        Next i
    
    
    End Sub
    

    I'm curious to know if this works for others, it just uses the "replace" 0 values to blanks, then uses specialcells to delete the blank rows. My test of 38K rows takes 3 seconds.

        Sub FindLoop()
    
        Dim startTime As Single
        startTime = Timer
    
    
        '--------------------------
    
    
        Columns("D:D").Replace What:="0", Replacement:="", LookAt:=xlPart, _
                               SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
                               ReplaceFormat:=False
        Columns("D:D").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    
    
    
        '---------------------------------
        Debug.Print Timer - startTime
    End Sub
    

提交回复
热议问题