VBA Progress Bar

Last Updated :

11 May, 2019

Edited by :

Reviewed by :

Download FREE VBA Progress Bar Template and Follow Along!
VBA Progress Bar Template.xlsm

Table Of Contents

arrow

Excel VBA Progress Bar in Excel

Progress Bar shows us how much of a process has been done or finished. For example, when we run large sets of codes that require a larger execution time, we use the progress bar in VBA to show the user the status of the process. Or, if we have multiple processes running in a single code, we use the progress bar to show which process has progressed and how much.

A progress bar shows the percentage of tasks completed when the actual task is running behind the screen with a set of instructions given by the code.

When the VBA code takes a considerable amount of time to execute, it is the user’s anxiety to know how soon it can finish. By default, we need to wait for the full time to complete the task, but by inserting the progress bar, we get to know the progress of the VBA code.

In almost all computer software, we see a progress bar chart that shows the progress of the task we are performing, just like the below image.

Progress-Bar

In Excel, we can create a progress bar by using VBA coding. If you have ever wondered how we can create a progress bar, this is the tailor-made article for you.

Create Your Own Progress Bar

To create a progress bar, we need to follow several steps. Below are the steps to involve while creating the progress bar chart.

Step 1: Create or Insert a new UserForm.

VBA-ProgressBar-Step-1

As soon as you click on the option above, you will see a UserForm like the one below.

VBA-ProgressBar-Step-1.1

Step 2: Press the F4 key to see the VBA Properties window.

VBA ProgressBar Step 2

In this Properties tab, we need to change the properties of the VBA Userform we have inserted.

Step 3: Change the name of the UserForm to UFProgressBar.

VBA-ProgressBar-Step-3

Now, we can refer to this UserForm with the name “UFProgressBar” while coding.

Step 4: Change the "Show Modal" property of the UserForm to "FALSE."

VBA-ProgressBar-Step-4

Step 5: Now, adjust the user's alignment to fit your needs. We have changed the height of the UserForm to 120 and the width to 300.

VBA-ProgressBar-Step-5

VBA-ProgressBar-Step-5.1

Step 6: Change the "Caption" of the UserForm to "Progress Bar."

VBA-ProgressBar-Step-6

Step 7: Now, from the toolbox of the UserForm, insert LABEL to the UserForm at the top.

VBA-ProgressBar-Step-7

With this label, we need to set the properties of the label. First, delete the caption, make it blank, and adjust the width of the label.

VBA-ProgressBar-Step-7.1

VBA-ProgressBar-Step-8

Step 8: Change the "Name" of the label to "ProgessLabel."

VBA-ProgressBar-Step-8-1

Step 9: Take the frame from the toolbox and draw just below the label we inserted in the previous steps. Make sure the frame is at the center of the UserForm.

VBA-ProgressBar-Step-9

Step 10: We need to change some of the frame's properties to make it look the same as the UserForm we have inserted.


Property 1: Change the "Name" of the frame to "ProgressFrame."

VBA-ProgressBar-Step-10

Property 2: Delete the "Caption" and make it blank.

VBA-ProgressBar-Step-10.1

Property 3: Change the "SpecialEffect" of the frame to 6 – fmSpecialEffectBump.

VBA-ProgressBar-Step-10.2-1

After all these changes, our UserForm should look like this.

VBA-ProgressBar-Step-10.3

Step 11: Now, insert one more label. This time insert the label just inside the frame we have inserted.

VBA-ProgressBar-Step-11
While inserting the label, ensure the left side of the label exactly fits the frame we have inserted, as shown in the above image.

Step 12: After inserting the label, change the label's properties as follows.

Property 1: Change the "Name" of the label to "MainProgressLabel."

VBA-ProgressBar-Step-12

Property 2: Delete the "Caption."

VBA-ProgressBar-Step-12.1

Property 3: Change the background color as per your wish

VBA-ProgressBar-Step-12.2

Now, we have completed setting up the progress bar. At this point, it looks like this.

VBA-ProgressBar-Step-12.3

Now, we need to enter codes to make this work perfectly.

Step 13: To make the framework add the below macro in excel.

Code:

Sub InitUFProgressBarBar()

With UFProgressBar 
.Bar.Width = 0 
.Text.Caption = "0%" 
.Show vbModeless

End With

Note: “UFProgressBar” is the name given to the UserForm, "Bar" is the name given to the frame we have created, and "Text" is the name given to the label inside the frame.

Now, if you run this code manually or through the F5 key, we should see the progress bar like this.

VBA-ProgressBar-Step-13.1

Step 14: We need to create a Macro to perform our task. We are performing the task of inserting serial numbers from 1 to 5,000. We also need to configure the progress bar chart along with this code. The code is tailor-made code for you.

Code:

Sub ProgressBar_Chart()

Dim i As Long 
Dim CurrentUFProgressBar As Double 
Dim UFProgressBarPercentage As Double 
Dim BarWidth As Long

i = 1

Call InitUFProgressBarBar

Do While i <= 5500

Cells(i, 1).Value = i

CurrentUFProgressBar = i / 2500 
BarWidth = UFProgressBar.Border.Width * CurrentUFProgressBar 
UFProgressBarPercentage = Round(CurrentUFProgressBar * 100, 0)

UFProgressBar.Bar.Width = BarWidth UFProgressBar.Text.Caption = UFProgressBarPercentage & "% Complete"

DoEvents

i = i + 1

Loop

Unload 

UFProgressBar

End Sub

VBA-ProgressBar-Step-14