Avoid activating and selecting - danielep71/VBA-PERFORMANCE GitHub Wiki

Home


When recording a Macro, you will get many Activate and Select methods:

Sub Slow_Example()
    Sheets("Sheet2").Select
    Range("D9").Select
    ActiveCell.FormulaR1C1 = "example"
    Range("D12").Select
    ActiveCell.FormulaR1C1 = "demo"
    Range("D13").Select
End Sub

Activating and selecting objects is usually unnecessary, they add clutter to your code, and they are very time-consuming. You should avoid this method when possible.

Improved Example:

Sub Fast_Example()
    Sheets("Sheet2").Range("D9").FormulaR1C1 = "example"
    Sheets("Sheet2").Range("D12").FormulaR1C1 = "demo"
End Sub

Home