VBA:快速有效地删除行

时间:2017-07-20 08:53:12

标签: excel vba excel-vba delete-row processing-efficiency

我的解决方案需要很长时间才能执行。我有60k行的文件,它可以更大。你能帮助我加快这个过程吗?

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

1 个答案:

答案 0 :(得分:2)

可以尝试将计算设置为手动和禁用事件

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

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True