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

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,224,927
Messages
6,181,799
Members
453,067
Latest member
cernytomas

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