LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default Interrupting a Loop

Private Sub CommandButton1_Click()

Dim ctr As Long
Dim StartNum As Integer

StartNum = 0

Range("B2").Select

While StartNum <= 9
Range("B2") = StartNum
StartNum = StartNum + 1
While ctr < 600000
ctr = ctr + 1
Wend
ctr = 1
If StartNum = 10 Then
StartNum = 0
End If
Wend

End Sub


I have two buttons in sheet1, "Start" and "Stop"
When I click the "Start" button, it runs the above code and increments
value in cell B2 but the mouse loses focus. I want to interrupt the
above code when I click the "Stop" button but it does not allow me to
click anywhere as the code is in Loop.

How can I click the "Stop" button?

I got a reply from forums to add "doevents" below ctr = ctr + 1 line to
get access to the stop button but the initial macro pauses to enable
events on the form. I am looking to multitask both, the loop and the
events.

Value in cell B2 should keep on incrementing and the moment user clicks
on the Stop button, it should stop.

Thanks
Maxi

 
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
Interrupting Calculation Iterations Andrew Lee[_2_] Excel Discussion (Misc queries) 0 July 13th 07 04:30 AM
Interrupting A Worksheet Calculation carl Excel Worksheet Functions 2 November 22nd 05 07:18 PM
Interrupting an endless loop davegb Excel Programming 3 March 17th 05 05:06 PM
Interrupting a loop Andrea[_8_] Excel Programming 1 April 27th 04 07:47 PM
Interrupting an add line Brian McGuire[_2_] Excel Programming 1 December 9th 03 07:39 PM


All times are GMT +1. The time now is 05:48 PM.

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

About Us

"It's about Microsoft Excel"