VBA looping

  • Thread starter Thread starter Mdelta
  • Start date Start date
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
 
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
 
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
 
Hi Mark,
Just noticed I accidentally dimensioned blnStop as Variant.

It should be...

Public blnStop as Boolean

Trivial I know!

Ken Johnson
 

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

Back
Top