Excel VBA – VBA performance Optimization

Optimizing VBA code

Sample file downloadhttps://github.com/dannyyun/pivot-vba.git

Add ‘OptimizeCode_Begin’ to the first line inside sub, and add ‘OptimizeCode_End’ to the last line inside sub.


Sub OptimizeCode_Begin()
    
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Application.Calculation = xlCalculationManual

End Sub

Sub OptimizeCode_End()
    
    ActiveSheet.DisplayPageBreaks = True
    Application.Calculation = xlCalculationAutomatic
    Application.EnableEvents = True

End Sub

Example of usage

Sub GroupBy()

    OptimizeCode_Begin

    'Enter your code between optimize code begin/end

    OptimizeCode_End

End Sub

Leave a Reply

Discover more from this and that @ work

Subscribe now to keep reading and get access to the full archive.

Continue reading