How Do DoEvents and Application.Wait Work in Excel VBA Chart Animation?
Question details
Understand how DoEvents and Application.Wait affect an Excel VBA chart animation.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A VBA loop updates cells that supply data to a chart and needs to display each change at a controlled pace.
- Observed behavior
- DoEvents yields control so Excel can process pending events, while Application.Wait pauses the macro and most Excel interaction for a specified time.
Make sure the chart uses the cells your macro will update. Open the VBA editor and check that macros are enabled for the workbook before running an example.
Use DoEvents to Refresh the Chart and Wait to Control Speed
Use this approach when a VBA loop should show each chart update before pausing between frames.
DoEvents temporarily yields control to the operating system and returns to the macro after pending events are processed. Application.Wait pauses the macro until a specified time; background recalculation and printing may continue.
Because DoEvents can allow other events to run, avoid starting the same macro again while it is already running.
In Excel, open the Developer tab and select Visual Basic, then choose Insert > Module. If the Developer tab is hidden, open the VBA editor with the shortcut available on your system.
Paste this example into the module. Replace Sheet1 with the worksheet name and A1 with a cell used by your chart: Sub AnimateChart() Dim i As Long Application.ScreenUpdating = True For i = 1 To 10 Worksheets("Sheet1").Range("A1").Value = i Worksheets("Sheet1").Calculate DoEvents Application.Wait Now + TimeValue("00:00:01") Next i End Sub
In Excel, select Developer > Macros, choose AnimateChart, and select Run. Change the loop values or the Wait duration to suit the animation; remove the Wait line if no deliberate pause is needed.

Work with Spreadsheet Charts in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and Microsoft Office format compatibility for easier migration. The Excel-specific VBA behavior described here must be tested separately if you move a macro-enabled workbook.

Frequently Asked Questions
Does DoEvents stop a VBA macro?
No. DoEvents temporarily yields control to process pending events, then execution returns to the next statement in the macro.
Why doesn't Application.Wait refresh my chart?
Application.Wait pauses the macro rather than explicitly refreshing the chart. After updating the source cell, calculate the relevant worksheet and call DoEvents before the Wait statement.
Can Excel do anything while Application.Wait is running?
Most Excel interaction is suspended during the wait, but background recalculation and printing may continue.
Can DoEvents cause a macro to run twice?
DoEvents can let pending events or user actions run before the current macro finishes. Prevent the same procedure from being started again, for example by using a running-state flag.




