Progress Bar

Hans810

Board Regular
Joined
Dec 1, 2005
Messages
63
Hi All,

During VBA calculations I would like to show a progress bar, so the users can see that the system is busy.
Who can help me with the VBA for this.

Thanks in advance and have a nice Sunday

Regards from Holland
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
In brief:-
  • when you start your VBA calculations, set the minimum and maximum values of the progress bar to some variable which your calculation can measure; set the value of the progress bar to the minimum value; make the progress bar visible
  • as the variable changes, set the value of the progress bar to the value of the variable
  • when your calculations end, make the progress bar invisible again
Of course this implies that you know in advance how many loops your code is going to make, how many records it's going to read, etc - otherwise you can't know in advance when you've completed 1%, 2%, etc.

Example:-
Code:
[FONT=Fixedsys]Option Explicit[/FONT]
[FONT=Fixedsys][/FONT] 
[FONT=Fixedsys]Public Sub DemoProgressBar()[/FONT]
[FONT=Fixedsys][/FONT] 
[FONT=Fixedsys]  Dim iLoop As Integer[/FONT]
[FONT=Fixedsys][/FONT] 
[FONT=Fixedsys]  With ThisWorkbook.Sheets("Sheet1")
    .ProgressBar1.Value = 0
    .ProgressBar1.Min = 0
    .ProgressBar1.Max = 100[/FONT]
[FONT=Fixedsys]    .ProgressBar1.Visible = True
  End With
   
  For iLoop = 1 To 100    
[COLOR=green]    ' do some processing[/COLOR][/FONT]
[FONT=Fixedsys]    With ThisWorkbook.Sheets("Sheet1")
      .ProgressBar1 = .ProgressBar1.Value + 1[/FONT]
[FONT=Fixedsys]    [COLOR=green]  ' or
[/COLOR]      .ProgressBar1 = iLoop[/FONT]
[FONT=Fixedsys]    End With
  Next iLoop
  
  MsgBox "Done!"
  
  With ThisWorkbook.Sheets("Sheet1")
    .ProgressBar1.Visible = False
  End With
  
End Sub[/FONT]
 
Upvote 0
Hi Ruddles,

Thanks for the response.
Can you tell me where to put the code you sent me?
I tried to put it in a loop as a separate module, but that does work.
I get error message 438 (property or mrthodnot supported by this object)
 
Upvote 0
Can you tell me where to put the code you sent me?
It's only an example. Place it in a standard code module in a new workbook if you want to test it but you'll need to put something in where it says "do some processing" to slow it down so it's visible - try Application.Wait Now() + TimeValue("00:00:01").

You have to create the ActiveX progress bar on the Sheet1 before you run the code.

If you read through the code you should be able to understand what each statement does. Get it working on its own first, then you can apply the principles to your own workbook.
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,792
Members
452,942
Latest member
VijayNewtoExcel

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