Beautiful VBA Progress Bar With Step by Step Instructions
Beautiful VBA Progress Bar With Step by Step Instructions
com
Introduction
Make your macros stand out by creating this beautiful VBA Progress Bar to illustrate the progress. This tutorial
walks you through how to make the sleek UserForm and how to implement it in your next project!
Inclusion of a VBA progress bar is an incredibly useful feature when you have long macros that take several
minutes to complete. Without a periodic status update, your users will wonder if the macro is still
running. Follow this step-by-step guide to learn how to incorporate a progress bar into your own spreadsheet.
To get you motivated about what’s in store, I’m going to go ahead and show you the final design of my VBA
progress bar:
https://wellsr.com/vba/2017/excel/beautiful-vba-progress-bar-with-step-by-step-instructions/ 1/13
8/18/22, 11:42 PM Beautiful VBA Progress Bar with Step by Step Instructions - wellsr.com
The first thing we want to do is create a UserForm and add the elements necessary to turn it into a progress
bar. If you’re new to VBA, follow these steps to add a UserForm:
Here’s what my Progress Bar looks like after completing these steps:
https://wellsr.com/vba/2017/excel/beautiful-vba-progress-bar-with-step-by-step-instructions/ 2/13
8/18/22, 11:42 PM Beautiful VBA Progress Bar with Step by Step Instructions - wellsr.com
Insert Label
1. Insert a label in the upper left of your UserForm. This will be used later to display the text indicating the
status of your macro.
2. Make sure the label is wide enough for any text you may display later. I set my Width property to 174 , but
there’s nothing magical about that number.
3. Change the (Name) of the label to LabelCaption .
4. Change the Caption property to an empty string (no text).
At this point, your Progress Bar should look something like this:
Insert Frame
The next step is to insert a Frame on your UserForm. The frame is the item highlighted in the Toolbox
screenshot below:
https://wellsr.com/vba/2017/excel/beautiful-vba-progress-bar-with-step-by-step-instructions/ 3/13
8/18/22, 11:42 PM Beautiful VBA Progress Bar with Step by Step Instructions - wellsr.com
You want to insert the frame so it’s roughly centered on your UserForm, both horizontally and vertically, with a
little margin on each side. It should be positioned below the label you previously added. At this point, your
UserForm will look something like this:
To make the frame begin to resemble a progress bar, you’ll need to change a few properties. Follow these
steps to configure the frame properties:
At this point, you can start to see the outline of your progress bar. The progress bar is finally starting to take
shape and will look something like this:
https://wellsr.com/vba/2017/excel/beautiful-vba-progress-bar-with-step-by-step-instructions/ 4/13
8/18/22, 11:42 PM Beautiful VBA Progress Bar with Step by Step Instructions - wellsr.com
1. Insert a label INSIDE the frame you just created, and change the height so it fits nicely right up against the
top and bottom of your frame.
2. Position the label so the left edge of the label touches the left edge of the frame. The width of the label
doesn’t matter at this point. It will look like this:
You are done designing your VBA Progress Bar! The UserForm will look something like this:
Once you get to this point, you’re ready to add the macros to your Progress Bar so it behaves the way we want
it to.
https://wellsr.com/vba/2017/excel/beautiful-vba-progress-bar-with-step-by-step-instructions/ 5/13
8/18/22, 11:42 PM Beautiful VBA Progress Bar with Step by Step Instructions - wellsr.com
To remove the title bar, I’m going to borrow a macro from my Remove Window Border tutorial. If the person
using the spreadsheet you’re creating is a Mac user, this macro won’t work, but I’ll show you how to prevent it
from crashing on them later.
https://wellsr.com/vba/2017/excel/beautiful-vba-progress-bar-with-step-by-step-instructions/ 6/13
8/18/22, 11:42 PM Beautiful VBA Progress Bar with Step by Step Instructions - wellsr.com
https://wellsr.com/vba/2017/excel/beautiful-vba-progress-bar-with-step-by-step-instructions/ 7/13
8/18/22, 11:42 PM Beautiful VBA Progress Bar with Step by Step Instructions - wellsr.com
1. Right click anywhere on your ufProgress form and select View Code
2. Clear out any macros that may appear on the form
3. Paste the following macro:
The IsMac check in this routine is what prevents the macro from crashing for users running Excel on a
Mac. Instead of the sleek UserForm without a title bar, they’ll see the title bar. In other words, their Progress
Bars won’t be as pretty as you Windows users, but that’s okay, right!? ;)
This is where you may have to adapt the solution I provide into your own application. This might require you to
think outside the box a bit, but I’m confident you can do that!
https://wellsr.com/vba/2017/excel/beautiful-vba-progress-bar-with-step-by-step-instructions/ 8/13
8/18/22, 11:42 PM Beautiful VBA Progress Bar with Step by Step Instructions - wellsr.com
The best way to show you how to include the progress bar in your macro is to give you a demonstration and
then walk you through the important pieces.
In this example, I loop through all the rows in my spreadsheet and update my progress bar after each
row. Here’s the sample macro (pay attention to the comment cards):
This sample has 3 important steps. These 3 steps are common whether or not your macro uses a For loop
like the one above.
https://wellsr.com/vba/2017/excel/beautiful-vba-progress-bar-with-step-by-step-instructions/ 9/13
8/18/22, 11:42 PM Beautiful VBA Progress Bar with Step by Step Instructions - wellsr.com
ufProgress.LabelProgress.Width = 0
ufProgress.Show
pctdone = i / lastrow
With ufProgress
.LabelCaption.Caption = "Processing Row " & i & " of " & lastrow
.LabelProgress.Width = pctdone * (.FrameProgress.Width)
End With
DoEvents
Each time I get to a new row, I update the LabelCaption text and the width of my LabelProgress label.
This is a great way to indicate progress if your macro consists of a loop where you know the starting position
and you know the ending position. Examples where a solution like the one above will work are when you’re
processing each line of data in a spreadsheet, or looping through files in a folder.
https://wellsr.com/vba/2017/excel/beautiful-vba-progress-bar-with-step-by-step-instructions/ 10/13
8/18/22, 11:42 PM Beautiful VBA Progress Bar with Step by Step Instructions - wellsr.com
The important part is, you need to follow the same 3 steps.
You don’t need a formula to do this. You could manually update the progress bar at various points in your
macro. Take a look at this demonstration, where I include the same 3 steps but they’re manually sprinkled into
my existing macro.:
https://wellsr.com/vba/2017/excel/beautiful-vba-progress-bar-with-step-by-step-instructions/ 11/13
8/18/22, 11:42 PM Beautiful VBA Progress Bar with Step by Step Instructions - wellsr.com
End Sub
In this example, I spaced out my macro so I could provide a status update at approximate 1/4 intervals. How
you split your macro isn’t important. As long as you’re periodically updating your LabelCaption text and
your LabelProgress width, your users will be happy.
https://wellsr.com/vba/2017/excel/beautiful-vba-progress-bar-with-step-by-step-instructions/ 12/13
8/18/22, 11:42 PM Beautiful VBA Progress Bar with Step by Step Instructions - wellsr.com
ufProgress.Repaint
This short piece of code forces VBA to redraw your progress bar so it’s updated each time the UserForm
changes.
Final Thoughts
You have successfully created an incredible progress bar using VBA that your users will surely be thankful
for! Get creative and change your caption text to specifically match what your macro is doing at any given point
if you’d like. When I need to mass produce PDF invoices, I’ve included a progress bar like this one to keep me
updated on the status. You can do the same!
https://wellsr.com/vba/2017/excel/beautiful-vba-progress-bar-with-step-by-step-instructions/ 13/13