Home > Software design >  Can the following VBA code subs be improved for faster calculation?
Can the following VBA code subs be improved for faster calculation?

Time:11-10

  Sub CAL()

  'Cleans the data before analysis by removing unwanted fields

    
    Dim wb          As Workbook
    Dim ws          As Worksheet
    Dim rng         As Range
    
    Set wb = ThisWorkbook
    
    
    Range("$H$1:$T$20000").AutoFilter Field:=1, Criteria1:=Array( _
                                                  "Customer Informations", "Customer Sale Statistic", "=", "Date:", "Group:", "Level:", _
                                                    "Real Value - 001", "2", "7", "3", "9", "12", "Target:"), Operator:=xlFilterValues
    Range("H2:T20000").ClearContents
    
    ActiveSheet.ShowAllData

End sub
    

CodePudding user response:

Probably not much but it might help a bit to deactivate calculation (if there are formulas) and screen updating:

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Range("$H$1:$T$20000").AutoFilter Field:=1, Criteria1:=Array( _
                                              "Customer Informations", "Customer Sale Statistic", "=", "Date:", "Group:", "Level:", _
                                                "Real Value - 001", "2", "7", "3", "9", "12", "Target:"), Operator:=xlFilterValues
Range("H2:T20000").ClearContents


Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
  • Related