Search code examples
vbaexceldelete-rowprocessing-efficiency

VBA: Speed efficient deleting rows


My solution takes a long time to execute. I have file with 60k rows, and it can be bigger. Can you help me to make this process faster?

Sub kary()

Dim table As Variant
Dim Wb As Workbook
Dim liczba, i As Long

Application.ScreenUpdating = False

Set Wb = Application.ActiveWorkbook

table = Wb.Worksheets("raport").Range("A1").CurrentRegion

i = 8
While Cells(i, 1) <> ""
    If Cells(i, 11) <= 0 Or Cells(i, 5) = "FV_K" Or Cells(i, 5) = "KFD" Or Cells(i, 5) = "KR" Then
        Rows(i).Delete Shift:=xlUp
    Else
        i = i + 1
    End If
Wend

Application.ScreenUpdating = True

End Sub

Solution

  • Can try setting calculation to manual and disabling events

    'Optimise code performance
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Application.EnableEvents = False
         .
         .
         .
    
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
    Application.EnableEvents = True