|
For most short Excel macros, especially when you’re just starting to learn VBA coding, the code seems to execute instantaneously. But as the code you creates gets longer, manipulates more variables, and stores more values, it requires more of your computer’s calculating powder, which can slow down the execution. Here are a few tips to help you speed up your VBA code in Excel: - Make sure to declare all your variables as a specific data type.
- If you reference an object (such as a range) more than once, create an object variable by using the Set keyword.
- Use the With-End With construct whenever possible.
- If your macro writes data to a worksheet and you have lots of complex formulas, set the calculation mode to Manual while the macro runs. (But make sure you do a calculation when you need to use the results!)
- If your macro writes information to a worksheet, turn off screen updating by using Application.ScreenUpdating = False.
Don’t forget to reinstate these last two settings to their starting values when your macro is finished.
|