#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default CTRL +BREAK

Is there a way to create a button that stops a series of "iterations" - the
equivalent of CTRL+BREAK

how?

Moiz


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default CTRL +BREAK

Here is a simple example:

Public Interrupt As Boolean

Public Sub TEST()
Interrupt = False
For i = 1 To 30000
If Interrupt Then Exit For
Range("A1").Value = i
DoEvents
Next i
End Sub

Sub Button1_Click()
Interrupt = True
End Sub

Key elements:
- Public variable that gets set to a particular value when button pressed
- In your sub containing the loop you need to "preset" the value of the
variable so the loop will run
- Important! Include a DoEvents statement inside the loop. Without it the
button press will not be detected until the loop ends.
- Have some way of terminating the loop when the value of the public
variable gets set by the button. Above I use an Exit For statement, but
personally I don't like that approach (I am an old-time structured
programmer). I prefer to do a While loop in the form of:
While .... And Not Interrupt.
' loop code
Wend
-
--
- K Dales


"Moiz, ABAC UK" wrote:

Is there a way to create a button that stops a series of "iterations" - the
equivalent of CTRL+BREAK

how?

Moiz



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
Ctrl+Alt+Break Tom Excel Programming 0 April 13th 05 12:22 PM
Can Not Get Macro to Break with CTRL-BREAK Break Me? Excel Programming 0 September 8th 04 03:15 AM
How to disable Ctrl+Break No Name Excel Programming 1 April 23rd 04 02:17 PM
Stopping a macro without using Ctrl Break Julian[_2_] Excel Programming 1 October 27th 03 02:39 AM
How to disable the Ctrl+Break ? Krzysztof Klimczak Excel Programming 1 July 31st 03 02:21 PM


All times are GMT +1. The time now is 09:41 AM.

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"