Progress Bar

bradyboyy88

Well-known Member
Joined
Feb 25, 2015
Messages
562
I am creating a progress bar on my userform and was curious if there was a way to count the total number of lines of code within a subroutine for the vb editor and also find an exact line in vb editor where something is executed within a subroutine. If this is doable then I can create a pretty reasonable progress bar that adjust the width of a frame based on the line/total lines formula from the methods mentioned above.
 
Last edited:

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Depending on the complexity of your code, you could tag each line of code with a small routine that will be executed at the end of each line ... You could also add line numbers to your code and use the Erl Property in a similar fashion :

The following example worked for me :
Add 1 Label and 1 commandbutton to a fresh userform and place the following code in its module :

Code:
Option Explicit

Private Sub CommandButton1_Click()

    Dim x As Long, y As Long:      UpdateProgressLabel
    
    Label1.Width = Me.InsideWidth: UpdateProgressLabel
    x = 1:                         UpdateProgressLabel
    x = 2:                         UpdateProgressLabel
    x = 3:                         UpdateProgressLabel
    MsgBox "hello":                UpdateProgressLabel
    x = 4:                         UpdateProgressLabel
    x = 5:                         UpdateProgressLabel
    For y = 1 To 10
                                   UpdateProgressLabel
    Next
    x = 6:                         UpdateProgressLabel
UpdateProgressLabel:      Unload Me

End Sub

Private Sub Delay(TimeOut As Single)
    Dim t As Single
    t = Timer
    Do
        DoEvents
    Loop Until Timer - t >= TimeOut
End Sub

Private Sub UpdateProgressLabel()
    Static i As Long
    i = i + 1
    Label1.Caption = "Current Code Line executing is : " & i: Delay 0.5
End Sub
 
Upvote 0
Yea I think the tag method is easiest. I am going to use a loading bar rather than a caption. Have you ever played around with the window frame to add objects to it that can change in width, ie a load bar rectangle?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,180
Members
453,021
Latest member
Justyna P

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