VBA userform progress bar for cycles (just sharing my code)

CsJHUN

Active Member
Joined
Jan 13, 2015
Messages
360
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
  2. Mobile
Hi guys, i googled and forumed many solution for progressbars. Some are way above my head (with kernel inputs, hardware keys, so on), so i try to made one for myself which easily readable and understandable.
I made a simple userform with 3 label. First is just for sub title, third is for text output the current progress and the second for the actual bar, this is 200 pixel wide (this is why i multiple the width by 2)
VBA Code:
Private Sub UserForm_Activate()
inital_value = Range("F4").Value 'as not always 1, it should be 0<
end_value = Range("F5").Value 'as not always 1, it should be (0< & inital_value<
repetion_count = end_value - inital_value
percent_per_repetition_count = 100 / repetion_count

lbl_progress_bar.Width = 0
For i = 1 To repetion_count
lbl_progress_bar.Width = i * percent_per_repetition_count * 2
Application.ScreenUpdating = True
lbl_progress_bar_text.Caption = i & " / " & repetion_count & " (" & Format(i * percent_per_repetition_count/ 100, "0.0%") & ")"
Application.Wait (Now + 2 / 24 / 60 / 60) 'just to see anything happens
Me.Repaint
Application.ScreenUpdating = False
Next i
End Sub

Hope you like it, enjoy coding :D
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,223,966
Messages
6,175,662
Members
452,666
Latest member
AllexDee

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top