Increase VBA performance

If your macro include code to make many change in sheets, document, jumping in/out of them then you need to consider to turn off screen update to turning performance of your code. Consider following snip-set example. Comment out the red line to see the effect

Sub myMacro ()

    On Error Goto errLabel
    Application.ScreenUpdating = False

    for i =1 to 1000 

        With Sheets("Sheets1")
           .Select
           .Activate
           Cells(i,1).Value=i
        End With
        With Sheets("Sheets2")
           .Select
           .Activate
           Cells(i,1).Value=i
        End With
    next
exitLabel:

    Application.ScreenUpdating = True
    Exit Sub

errLabel:
    MsgBox "System stop processing with error: " & Err.Description, vbOKOnly + vbCritical,"HotIce Soft"
    Resume exitLabel
    Resume Next
End Sub
Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s