Speed Up Macros

How to optimize your macros to run faster. Watch the video below:

Speed Up Macros
  1. Turn Off Screen Updating:

To turn off screen updating, use the following statement:

Application.ScreenUpdating = False

If we wish the user to see what action the macro is performing at a specific time, we can use the following statement to turn screen updating back on:

Application.ScreenUpdating = True

2. Turn Off Automatic calculations:

Sub No_Automatic_Calculations()
Application.Calculation = xlCalculationManual
‘…Other Lines of Code
Application.Calculation = xlCalculationAutomatic
End Sub

3. Disable display alerts

Example – Refer to the video

Sub FillRangeWithNumbers()

Dim row As Long, col As Long
Dim Number As Long
Number = 0
For row = 1 To 60
For col = 1 To 60
Number = Number + 1
Cells(row, col).Select
Cells(row, col).Value = Number
Next col
Next row
Application.DisplayAlerts = False
Application.DisplayAlerts = True

End Sub

4. Simplify Object References
Instead of
We can write:
Set GST = Workbooks(“MyBook.xlsx”).Worksheets(“Sheet1”).Range(“Z2”)


5. Declaring Variable Types – each of the variables is declared with its data type.

Dim I as Long

Dim MyName as String

Dim Employees() as String

6. Use ‘WITH’ Statement

Instead of
Sub No_WITH()
Worksheets(“Sheet1″).Range(“B1”).Value = 500
Worksheets(“Sheet1″).Range(“B1”).Font.Bold = True
End Sub
We code like this:
Sub Use_WITH()
Set ws = ThisWorkbook.Worksheets(1)
With ws.Range(“B1″)
.Value = 500
.Font.Bold = True
End With
End Sub

7. Copy and Paste

Best is to use the following approach instead of copy, select and paste:
Sub CopyPaste()
Sheets(“Sheet1”).Range(“B1:F10”).Copy Destination:=Sheets(“Sheet2”).Range(“B1”)
End Sub

8. Using VBNullString for Placing Blanks in Worksheet Cells is faster than using “” Double Quotes.

Speed up macros by setting display alerts to false
Display Alerts Set to TRUE

The above are some of the simple steps that we can undertake to make our macros or VBA code execute faster.

Published by

Dinesh Kumar Takyar

Welcome to exceltrainingvideos.com! My aim is to help you learn MS Excel including VBA. I always felt that a good way to learn something was to find solutions to problems in that domain. That is why I share these Excel videos with you. Mostly these are questions asked during my corporate training sessions. I've been training individuals and companies in computers since 1991. I did my B. Sc. (Vordiplom), M. Sc. (Diplom) and Ph.D. (Dr. rer. nat.) from Hamburg, Germany. The best thing about solving some of my visitor's questions is that I also gain new insights. For more Excel VBA solutions you may like to visit my YouTube channel: http://youtube.com/familycomputerclub For a structured Excel VBA training course online you can visit: https://www.youtube.com/excelvbaonline

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.