create a progress bar for a sequence of macros

tommy1234

New Member
Joined
Aug 24, 2011
Messages
20
Hello

I need to create a progress bar (i found the code on the web) for many macros (the macros are running in a sequence).
i have 4 subs, and i want that the progress bar will start when i click the button and will finish when the last macro will finish to run.

Code:
Sub code()

Dim i As Integer, j As Integer, pctCompl As Single


Sheet5.Cells.Clear


For i = 1 To 100
     For j = 1 To 1
         Worksheets("sheet1").Cells(1, 1).Value = j
     Next j
     pctCompl = i
     progress pctCompl
Next i


End Sub


Sub progress(pctCompl As Single)


 UserForm2.Text.Caption = pctCompl & "% Completed"
 UserForm2.Bar.Width = pctCompl * 2
 
 DoEvents


End Sub

thank you
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hello

To use this example, execute the RunMe procedure:

Code:
' UserForm module
Private Sub UserForm_activate()
Main
End Sub

Code:
Option Explicit
' standard module
Dim Counter#, RowMax#, ColMax#, r%, c%, PctDone#

Sub RunMe()
UserForm1.Show
End Sub

Sub Main()
'   Inserts random numbers on the active worksheet
    If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
    Cells.Clear
    Application.ScreenUpdating = False
    First
    Second
    Third
    Fourth
    Unload UserForm1
End Sub

Sub UpdateBar(start!)
PctDone = start + Counter / (RowMax * ColMax * 4)
With UserForm1
    .FrameProgress.Caption = Format(PctDone, "0%")
    .LabelProgress.Width = PctDone * (.FrameProgress.Width - 10)
End With
DoEvents
End Sub

Sub First()
Counter = 1
RowMax = 1000
ColMax = 250
For r = 1 To RowMax
    For c = 1 To ColMax
        Cells(r, c) = Int(Rnd * 1000)
        Counter = Counter + 1
    Next
    UpdateBar 0
Next
End Sub

Sub Second()
Counter = 1
RowMax = 500
ColMax = 200
For r = 1 To RowMax
    For c = 1 To ColMax
        Cells(r, c) = Int(Rnd * 1000)
        Counter = Counter + 1
    Next
    UpdateBar 0.25
Next
End Sub

Sub Third()
Counter = 1
RowMax = 800
ColMax = 210
For r = 1 To RowMax
    For c = 1 To ColMax
        Cells(r, c) = Int(Rnd * 1000)
        Counter = Counter + 1
    Next
    UpdateBar 0.5
Next
End Sub

Sub Fourth()
Counter = 1
RowMax = 900
ColMax = 220
For r = 1 To RowMax
    For c = 1 To ColMax
        Cells(r, c) = Int(Rnd * 1000)
        Counter = Counter + 1
    Next
    UpdateBar 0.75
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,830
Messages
6,121,839
Members
449,051
Latest member
excelquestion515

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