VBA looping

M

Mdelta

I am working on a VBA script which I want to loop until it fills all
rows in excel, or the user stops it by clicking a button.

By hitting ESC it will take out all delays that I have in the script
and the script will finish off the number of "loops"--I would like to
have a "STOP" command button where the script stops then resets.

Any information that you can provide will be appreciated.

Thanks in advance
Mark
 
K

Ken Johnson

Mdelta said:
I am working on a VBA script which I want to loop until it fills all
rows in excel, or the user stops it by clicking a button.

By hitting ESC it will take out all delays that I have in the script
and the script will finish off the number of "loops"--I would like to
have a "STOP" command button where the script stops then resets.

Any information that you can provide will be appreciated.

Thanks in advance
Mark

Hi Mark,

This seems to work...

Public blnStop

Public Sub loopy()
blnStop = False
Dim I As Long
Do
I = I + 1
DoEvents
Cells(1, 1).Value = I
Loop While Not blnStop
End Sub


Public Sub StopLoop()
blnStop = True
End Sub

Assign the StopLoop Sub to a Forms button.
The DoEvents statement enables the button to be operable while the
looping code is running.

Ken Johnson
 
M

Mdelta

This seems to work...

Public blnStop

Public Sub loopy()
blnStop = False
Dim I As Long
Do
I = I + 1
DoEvents
Cells(1, 1).Value = I
Loop While Not blnStop
End Sub

Public Sub StopLoop()
blnStop = True
End Sub

Assign the StopLoop Sub to a Forms button.
The DoEvents statement enables the button to be operable while the
looping code is running.

Ken Johnson

Thanks Ken
 
K

Ken Johnson

Hi Mark,
Just noticed I accidentally dimensioned blnStop as Variant.

It should be...

Public blnStop as Boolean

Trivial I know!

Ken Johnson
 
Top