How to Create Progress Bar in VBA

A progress bar is used in a computer application to indicate the progress of an operation. It’s commonly a rectangle that’s animated as an operation makes progress. Visual Basic for Applications, or VBA, is a computer programming language used in Microsoft Office Applications to automate routine tasks and to create user interfaces. You can easily create a progress bar using VBA in Microsoft Office Excel. Excel is a spreadsheet application included in the Microsoft Office suite.

...
Use Excel and VBA to create a progress bar.

Step

Open Microsoft Office Excel, then press “Alt” and "F11” to open the Visual Basic Editor. Right-click “VBAProject,” then click “UserForm” to insert a new Form. From the “Toolbox” menu, click “Label.” While holding your mouse button, drag on the Form to create a new label control.

Step

Right-click the label and select “Properties,” then change “Height” to 42 and “Width” to 12. Change the “Top” to 12. Create nine more labels using the same process.

Step

Click “CommandButton” on the “Toolbox” pane and add a new button to your Form. Right-click “CommandButton” and click “View Code” to create a new procedure.

Step

Type the following to create a new variable and define its value:

Step

Dim cnt As Integer cnt = 0

Step

Type the following to hide all the labels when the Form starts:

Step

Me.Label1.Visible = False Me.Label2.Visible = False Me.Label3.Visible = False Me.Label4.Visible = False Me.Label5.Visible = False Me.Label6.Visible = False Me.Label7.Visible = False Me.Label8.Visible = False Me.Label9.Visible = False Me.Label10.Visible = False

Step

Type the following to create a while loop and iterate 10 times while pausing the code for 5 seconds:

Step

Do While cnt <> 10

Step

cnt = cnt + 1

Step

Loop

Step

Click the “Insert” menu then click “Module” to add a new module. Copy and paste the code below to start your “UserForm1.”:

Step

Sub showProgressBar() UserForm1.Show End Sub

Step

Press “F5” to run your program.