ProgressBar Out of Sync

  • Thread starter Thread starter RDallas
  • Start date Start date
R

RDallas

Hope you can help, I have created a UserForm with multiple
CommandButtons, each CommandButton runs a lengthy Macro.
The Code for the Macro is running inside a loop that
updates a ProgressBar. I have this process running perfectly.
After you click the CommandButton, the Macro is in perfect
sync with the completion of the ProgressBar reaching 100%,
except that when the Userform that displays the ProgressBar
is instructed to unload, it unloads leaving a white area
where the UserForm was. The white area doesn't completely
disappear until the worksheet updates all of the changes,
about 12 seconds.
How can I make the UserForm remain displayed with the 100%
finished ProgressBar while the worksheet finishes it's 12
seconds of updating?
 
You could try
Application.Calculate
then unload progressbar

Or ...

Adapt the following code, of course the wait one second would be unnecessary
and you would have to calculate "i" yourself which you probably already do
anyway. I can't take credit for this code as one of the Gurus had it on his
site and gave credit again to someone else. Good Luck :)

Sub ProgressBarSimpleDemo()
Dim sb As clsProgressBar, i As Long
Set sb = New clsProgressBar ' create a new progress bar
sb.Show "Please wait", vbNullString, 0 ' display the progress bar
For i = 0 To 100 Step 20
sb.PercentComplete = i ' update the progress bar
WaitSeconds 1
Next i
Set sb = Nothing ' remove the progress bar
End Sub

Private Sub WaitSeconds(waitTime As Integer)
Application.Wait (Now + TimeValue("00:00:" & Format(waitTime, "00")))
End Sub
 
The white area could be the result of the code

Application.ScreenUpdating=False

somewhere. Try putting in the code Application.ScreenUpdating=TRUE
right before you unload the form.
 
Back
Top