Let user break out of a big computation?

R

Robert Crandal

I have a Userform which contains two buttons. One buttons
says "Begin" and the other button says "Cancel".

If the user presses "Begin", my macro will begin processing a
potentially long computation. Once the computation begins,
can I allow the user to press the "Cancel" button to break
out of the big computation?? Is that possible?

Additionally, is it possible to display some sort of progress
bar to display a percentage which shows how much of the
computation is complete? Would I need some sort of plug
control for this? Or can I just simply update a text label on
the form to show percentage completed??

Thank you!
 
H

Harald Staff

Hi

If your code knows how much is done and how much is left, then a progress
function is easy, simple percentage calculation.
http://spreadsheetpage.com/index.php/file/progress_indicator_demo/

If you know the steps but not the time, this is a good way of visualizing
the progress:
http://www.dailydoseofexcel.com/archives/2007/02/10/yet-another-progress-bar/

As for stopping the procedure, here is a very simple demo. All it does is
count up in the statusbar (lower left corner of Excel):

Option Explicit

Dim StopIt As Boolean

Sub BtnStartCode()
Dim m As Long, n As Long
StopIt = False
For m = 1 To 10000
DoEvents
If StopIt = True Then Exit Sub
For n = 1 To 999
Application.StatusBar = m * 1000 + n
Next
Next
End Sub

Sub BtnCancelCode()
StopIt = True
End Sub

HTH. Best wishes Harald
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top