View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default using a For-Next in a module and a Form

Because you are dealing with objects on the form, you cannot pause like you
are suggesting. What you will need to do is to exit that routine, and then
react to the button click. Something like

sub checkCells()
dim errorFound as Boolean
for I = 1 to 500
....
....
errorFound = FindErrors()
if errorFound = True then
frmCheckCells.lblErrorMessage.Caption = "Error found for i = "& i
Exit Sub
end if
....
....
next I
end sub


and then in the button click code, re-enter that routine, or whatever else
you need.

With a userform, as soon as the current macro finishes, as long as the form
is still visible, the app is effectively in pause.
--

HTH

RP
(remove nothere from the email address if mailing direct)


"coco" wrote in message
...
Hello,
I need same ideas because I do not know how to implement the "Start,
Continue, StartAllOver and Exit" buttons in the following Macro:

This is one module
sub checkCells()
dim errorFound as Boolean
for I = 1 to 500
....
....
errorFound = FindErrors()
if errorFound = True then
frmCheckCells.lblErrorMessage.Caption = "Error found for i = "& i
***PAUSE and WAIT for RESPONSE ***
end if
....
....
next I
end sub

And one form ( frmCheckCells ) with the following tools

4 buttons:
btnStartCheckingProcess, btnContinueCheckingProcess,
btnCancelCheckingProcess and btnStartAllOverCheckingProcess

And one Label (that will change for different kinds of error messages):
lblErrorMessage


What commands can I use to run this Macro correctly?
I would like to run it and then pause it when an error is found, prompt

for
what kind of error message (in the form), then wait for the user to select
the desire button.

Also I want to implement this macro without using the "MsgBox commands"
prompts.

Thanks

Coco