logo
search
VBA & Macro Problems

How to Display Excel VBA UserForm Updates While a Macro is Running

Camila MilosovichCamila Milosovich Sep 28, 2026 869 views

Question details

The user needs to update and display real-time progress on a VBA UserForm text box while a long-running macro loop is executing.

How to Refresh Excel VBA UserForms While a Macro is Running
Product
Excel VBA
Device & OS
not provided
Scenario
Running an intensive VBA macro loop that searches rows and writes calculation results to both worksheet cells and a UserForm.
Observed behavior
The UserForm freezes and does not refresh visually. It only displays the final updates after the macro completely finishes running, preventing real-time progress tracking.
Before you start

Ensure you have saved your workbook as a Macro-Enabled Workbook (.xlsm) to prevent any VBA code loss before modifying your UserForm properties.

Solution 1Recommended

Use DoEvents and Set UserForm ShowModal to False

By changing the UserForm to modeless and yielding execution with DoEvents, you allow the operating system to repaint the form during the macro loop.

When an Excel VBA macro runs, it monopolizes system resources to execute the code as quickly as possible. This prevents Windows from refreshing graphical elements like UserForms. The DoEvents function temporarily yields execution so the operating system can process queued events, such as updating text boxes on your form.

1
Change the ShowModal property

Press Alt + F11 to open the VBA Editor. In the Project Explorer, select your UserForm. In the Properties window (press F4 if hidden), locate 'ShowModal' and change its value to 'False'. Alternatively, display the form in your code using 'UserForm1.Show vbModeless'.

2
Insert DoEvents into your loop

Locate the long-running loop (e.g., For or Do While) in your macro module. Add the 'DoEvents' command inside the loop to force the screen to process visual updates.

3
Optimize performance with a Modulo operator

Because calling DoEvents on every single row will severely slow down your macro, wrap it in a condition to update periodically. For example, write 'If Row Mod 100 = 0 Then DoEvents' to refresh the UserForm only once every 100 iterations.

Use DoEvents and Set UserForm ShowModal to False
Performance Tip: Combining the Modulo (Mod) operator with DoEvents is the industry standard for VBA progress bars. It strikes the perfect balance between keeping the user informed and maintaining fast macro execution speeds.

Create and Run VBA Macros Seamlessly in WPS Spreadsheet

WPS Office provides excellent built-in support for VBA (Visual Basic for Applications). You can create custom UserForms, write automation macros, and utilize functions like DoEvents exactly as you would in Microsoft Excel.

  1. 1. Download and Install WPS Office: Get the free WPS Office suite from the official website and open WPS Spreadsheet.
  2. 2. Access the VBA Editor: Navigate to the 'Developer' tab on the top ribbon and click on 'Visual Basic', or simply press Alt + F11 to open the code editor.
  3. 3. Design your UserForm: Click 'Insert' > 'UserForm' to drag and drop text boxes or progress bars for your macro.
  4. 4. Write and Execute Code: Paste your Excel VBA macro code, utilizing the DoEvents function, and hit Run to see your real-time updates function perfectly.
Fully compatible with Microsoft Excel VBA scripts, UserForms, and macrosEasily build progress bars and interactive forms for your automation workflowsFree, lightweight, and fast alternative for robust spreadsheet automationFamiliar Developer tab interface ensures a zero-learning-curve migration
microsoft office alternative - wps office

Frequently Asked Questions

Why does my Excel macro freeze the screen and UserForm?

By default, Excel dedicates all available processing power to executing the VBA macro code as quickly as possible. This pauses background tasks like screen repainting, preventing the application or UserForms from updating until the code completes entirely.

What does the ShowModal property do in a VBA UserForm?

The ShowModal property determines whether a user must close the UserForm before interacting with the rest of the Excel application. Setting it to False (modeless) allows your VBA macro to continue running in the background while the form remains visible and updatable.

Does using DoEvents slow down my VBA macro?

Yes, calling DoEvents forces the macro to pause execution and hand control back to the operating system to process events like UI refreshes. Doing this on every loop iteration causes massive slowdowns, which is why it is highly recommended to use it with a modulo condition (e.g., If i Mod 100 = 0 Then DoEvents) to update periodically.

Can I use Application.ScreenUpdating instead of DoEvents to refresh a UserForm?

While setting Application.ScreenUpdating = True forces the worksheet to refresh, it often fails to repaint complex UserForms or ActiveX controls during an intensive loop. DoEvents is specifically required to process operating system messages, which includes repainting floating forms.