CTRL +BREAK
Is there a way to create a button that stops a series of "iterations" - the
equivalent of CTRL+BREAK how? Moiz |
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 |
All times are GMT +1. The time now is 12:33 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com