#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default End loop

I have a sub that runs continuously and I would like a better
way of stopping it other than pressing 'Esc' or 'Ctrl+Break'.
When I do press 'Esc' or 'Ctrl+Break' I end up with an error
message for debugging.

What I thought might be a possibility but I haven't got a clue
how to do it is to have a button that when clicked will -
"end the loop after this particular run" - can this be achieved?


Sub ContinuousLoop()
Do
*****Lots of Code*******
Loop
End Sub

Any ideas would be good.
Sandy

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default End loop

From the vba help index
Do...Loop Statement


Repeats a block of statements while a condition is True or until a condition
becomes True.

Syntax

Do [{While | Until} condition]
[statements]
[Exit Do]
[statements]

Loop

Or, you can use this syntax:

Do
[statements]
[Exit Do]
[statements]

Loop [{While | Until} condition]

The Do Loop statement syntax has these parts:

Part Description
condition Optional. Numeric expression or string expression that is
True or False. If condition is Null, condition is treated as False.
statements One or more statements that are repeated while, or until,
condition is True.



Remarks

Any number of Exit Do statements may be placed anywhere in the Do.Loop as an
alternate way to exit a Do.Loop. Exit Do is often used after evaluating some
condition, for example, If.Then, in which case the Exit Do statement
transfers control to the statement immediately following the Loop.

When used within nested Do.Loop statements, Exit Do transfers control to the
loop that is one nested level above the loop where Exit Do occurs.


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Sandy" wrote in message
...
I have a sub that runs continuously and I would like a better
way of stopping it other than pressing 'Esc' or 'Ctrl+Break'.
When I do press 'Esc' or 'Ctrl+Break' I end up with an error
message for debugging.

What I thought might be a possibility but I haven't got a clue
how to do it is to have a button that when clicked will - "end the loop
after this particular run" - can this be achieved?


Sub ContinuousLoop()
Do
*****Lots of Code*******
Loop
End Sub

Any ideas would be good.
Sandy


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default End loop

If your Do...Loop loop is running continuously, then obviously it is not
finding a condition that meets the While or Until criteria. You need to
review your code and revise it so that the logic will produce a result that
is either true or false based on what you tell the loop to evaluate.
Otherwise, you are wasting code.

"Sandy" wrote:

I have a sub that runs continuously and I would like a better
way of stopping it other than pressing 'Esc' or 'Ctrl+Break'.
When I do press 'Esc' or 'Ctrl+Break' I end up with an error
message for debugging.

What I thought might be a possibility but I haven't got a clue
how to do it is to have a button that when clicked will -
"end the loop after this particular run" - can this be achieved?


Sub ContinuousLoop()
Do
*****Lots of Code*******
Loop
End Sub

Any ideas would be good.
Sandy


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
returning back to loop check condition without completing the loop ashish128 Excel Programming 13 April 3rd 08 12:53 PM
Loop to Filter, Name Sheets. If Blank, Exit Loop ryguy7272 Excel Programming 3 February 5th 08 03:41 PM
(Complex) Loop within loop to create worksheets klysell Excel Programming 1 March 20th 07 12:03 AM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM


All times are GMT +1. The time now is 09:44 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"