I have downloaded the code from http://j-walk.com/ss/excel/tips/tip34.htm
I have created the userform or the progress bar, but am having a difficult time inderstanding where the codes go.
in my case I have a userform("reports") where users use checkboxes to determine the type of report they want to create. and then click the commandbutton1("Create") that, depending on which check boxes are true, runs other modules.
what I have done is have commandbutton1_click have ProgressBar.show instead of depending on which check boxes are true. and the code I use now in commandbutton1_click replace "call main" in the code below.
Private Sub UserForm_activate()
Call Main
End Sub
below would just be what ever module the userform_activate runs from above code.
Sub Main()
' Inserts random numbers on the active worksheet
Dim Counter As Integer
Dim RowMax As Integer, ColMax As Integer
Dim r As Integer, c As Integer
Dim PctDone As Single
If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
Cells.Clear
Application.ScreenUpdating = False
Counter = 1
RowMax = 100
ColMax = 25
For r = 1 To RowMax
For c = 1 To ColMax
Cells(r, c) = Int(Rnd * 1000)
Counter = Counter + 1
Next c
PctDone = Counter / (RowMax * ColMax)
With UserForm1
.FrameProgress.Caption = Format(PctDone, "0%")
.LabelProgress.Width = PctDone * (.FrameProgress.Width - 10)
End With
' The DoEvents statement is responsible for the form updating
DoEvents
Next r
Unload UserForm1
End Sub
and this should be at the at the end of ever module that could be ran from the userform_activate
Sub ShowDialog()
UserForm1.LabelProgress.Width = 0
UserForm1.Show
End Sub
but I can't seem to get it right. Any ideas?
Bookmarks