Turning off screen updating will only make a difference to execution time if the code interacts with Excel in a way that causes changes to the screen content. The greater the amount of screen changes the bigger the impact will be. The other posted answers aptly demonstrate this.
Other application settings that can make a difference to execution time are Calculation and Event handling. Use this code template as a starting point (the error handler ensures that these properties are turned back on at the end of the sub, even if it errors)
Sub YourSub()
On Error GoTo EH
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
' Code here
CleanUp:
On Error Resume Next
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Exit Sub
EH:
' Do error handling
Resume CleanUp
End Sub
Other techniques exist that can provide even greater improvement in execution speed.
The most useful include
- Avoid
Select
, Activate
and ActiveCell/Sheet/Workbook
as much as possible. Instead declare and assign variables and reference those.
- When referencing large ranges, copy the Range data to a variant array for processing and copy the result back to the range after.
- Use
Range.SpecialCells
, Range.Find
and Range.AutoFilter
to limit the number of cells referenced.
There are plenty of examples of these techniques on SO.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…