Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel VBA UserForm Progress Indicator: How to Build One

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

You can add a progress indicator to an Excel VBA UserForm by creating a second UserForm that holds a label or a frame, updating that label's width or caption inside your loop, and calling DoEvents after each update so the screen redraws. The shortest working set is: insert a UserForm, add a Label (or a Frame plus a Label inside it), set ShowModal = False, show it with UserForm2.Show vbModeless, then inside your processing loop set the label's width and call DoEvents once per iteration. That single line is what turns a frozen grey box into a moving bar.

What You'll Need

  • Excel on Windows with the Visual Basic Editor available (Alt+F11). The VBA UserForm designer is a Windows desktop feature; Excel for Mac and Excel for the web do not offer the same designer, so the steps below are for the Windows desktop app.
  • Macro-enabled workbook (.xlsm) with macros allowed.
  • A long-running procedure already written, or a test loop you can drop in.
  • Basic familiarity with the VBA editor: inserting modules and UserForms, and opening the Properties window (F4).

Step-by-Step

  1. Open the editor and insert a progress form. Press Alt+F11, then use Insert > UserForm. In the Properties window (F4), rename it to something clear such as frmProgress. Menu and dialog labels can differ slightly by Excel version and region, but Insert > UserForm is stable across Windows versions.
  2. Draw the bar. From the Toolbox, add a Frame to act as the outline of the bar, then add a Label inside that frame. Name the frame fraBar and the label lblBar. Set lblBar.Caption to an empty string, give it a visible BackColor (for example a blue), and set its Height to match the frame's inner height. Set the frame's BackColor to a light grey so the unfilled portion is visible.
  3. Add a status caption. Add a second Label called lblStatus below the bar. This is where you will write text like "Processing row 250 of 1,000". A percentage alone is fine, but a count helps users judge whether to wait.
  4. Make the form modeless. In the Properties window, set ShowModal to False. A modal form blocks the code that is trying to update it, which is the single most common reason progress bars never move. Also consider setting BorderStyle to fmBorderStyleNone so users cannot close the form mid-run.
  5. Add a public update routine. Right-click the form in the Project Explorer, choose View Code, and add a procedure such as:
    Public Sub UpdateProgress(ByVal pct As Double, ByVal msg As String)
    Inside it, clamp pct between 0 and 1, set lblBar.Width = fraBar.InsideWidth * pct, set lblStatus.Caption = msg, and end with DoEvents. Keeping the maths in one place means every caller behaves the same way.
  6. Show the form before the loop. In your main module, load and show the form with frmProgress.Show vbModeless before processing starts. Showing it first avoids a flash of an empty window halfway through.
  7. Update inside the loop. Inside your For or Do loop, call frmProgress.UpdateProgress i / total, "Row " & i & " of " & total. Do not call it on every single iteration if the loop runs hundreds of thousands of times; update every 50 or 100 rows instead, or when i Mod 100 = 0. Calling DoEvents too often slows the macro noticeably.
  8. Unload at the end, including on error. After the loop, call Unload frmProgress. Wrap the whole routine so the form is unloaded even if an error occurs: use On Error GoTo Cleanup, put Unload frmProgress in the cleanup block, and re-raise or report the error there. Otherwise a crash leaves a stray window on screen.
  9. Test with a deliberate delay. Before running it on real data, add a temporary loop of a few thousand iterations with DoEvents so you can see the bar move. If the bar jumps from empty to full instantly, your real task is too fast to need a progress indicator at all, which is a perfectly good outcome.

Common Mistakes

  • Leaving ShowModal as True. The form appears but never repaints, so it looks broken. Modeless is required for a live indicator.
  • Forgetting DoEvents. Without it, Windows does not process paint messages and the label width changes are invisible until the macro ends.
  • Setting the label width larger than the frame. Always multiply by the frame's inside width, not the form width, and clamp the result. Otherwise the bar spills outside its outline.
  • Not resetting between runs. If you reuse the form without unloading it, the bar starts full from the previous run. Reset width and caption when the form initialises.
  • Updating every iteration on a huge dataset. Each DoEvents hands control to Windows; thousands per second turn a fast macro into a slow one.
  • Assuming it works the same on Mac. The VBA UserForm designer is not available in Excel for Mac in the same form, so plan a different approach there.

Tips

  • Put the update logic in one public procedure on the form so every macro in the workbook calls the same code.
  • Show elapsed time or an estimated remaining time in lblStatus; it is often more useful than a percentage.
  • Use a Frame plus Label rather than a single label with a border, because the frame gives you a fixed outline that does not move as the label grows.
  • Keep the form small and non-resizable. A progress window is not a place for extra controls.
  • If the task can be cancelled, add a Cancel button that sets a module-level Boolean, and check it inside the loop. Remember to reset the flag at the start of each run.

Troubleshooting

The form appears but the bar never moves. Check ShowModal is False and that DoEvents is actually reached inside the loop. A common cause is an inner loop that never calls the update routine.

Excel shows "Not responding". The loop is doing heavy work without yielding. Add DoEvents at your chosen interval and reduce screen updates.

Error 424 or 91 when updating. The form was unloaded or never loaded when the update call ran. Show the form before the loop and unload only after it finishes.

The bar resets or starts full. Reset lblBar.Width and lblStatus.Caption in the form's Initialize event.

The macro is much slower than before. Lower the update frequency, for example every 100 iterations, and avoid recalculating the workbook inside the loop.

Frequently Asked Questions

Can I show progress without a second UserForm?

Yes. You can update a label on the existing form or write to the status bar with Application.StatusBar. A separate modeless form is cleaner because it stays visible while your other code runs.

Why does my progress bar only appear at the end?

Almost always because the form is modal or DoEvents is missing. Windows queues the repaint until your code yields.

Does DoEvents slow the macro down?

It can, because it lets Windows process other messages. Updating every 50 to 100 iterations is usually a good balance.

Can users close the progress form while it runs?

With a modeless form, yes, unless you handle it. Set the border style to none or intercept the QueryClose event and cancel the close while processing is active.

Does this work in Excel for Mac?

The VBA UserForm designer is a Windows desktop feature. On Mac, use the status bar or a simpler indicator instead.

How do I show a percentage instead of a bar?

Set lblStatus.Caption = Format(pct, "0%") and skip the width change. Many users find a percentage plus a row count clearer than a bar alone.