M
Maxi
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
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