Calculate Now function until button press

rikapple

New Member
Joined
Feb 17, 2014
Messages
45
Hi

For Xmas we are running a competition, basically a number drawn out of a hat. As this will be on teams I wanted to create some pazzaz on screen, I have added all the employee's names and crated a random function which works well every time I select the calculate now button,

What I wanted to do was have the calculate now continuing until a button is pressed. Possibly with .5second gap between the process. To give the effect the names are scrolling through. Then when button is pressed the Calculate now process stops.

Hope this is clear, any help is much apprechiated.

Stephanie
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Here is some code which hopefully does what you want, I created two buttons on the sheet one to start and one to stop which call the relevant macros Startrun and Stoprun. This code goes in a standard module. My code just increaments F4, I suggest you just call you randomising macro instead of that code:
VBA Code:
Public Stopflag As Boolean
Sub runnum()
Do While Not (Stopflag)
 Range("F4") = Range("f4") + 1
 If Range("f4") > 2000 Then Range("F4") = 0
 ' call your subroutine here instead of the last two lines of code
 DoEvents
Loop

End Sub

Sub Stoprun()
 Stopflag = True
End Sub
Sub Startrun()
Stopflag = False
Call runnum
End Sub
 
Upvote 0
Here is some code which hopefully does what you want, I created two buttons on the sheet one to start and one to stop which call the relevant macros Startrun and Stoprun. This code goes in a standard module. My code just increaments F4, I suggest you just call you randomising macro instead of that code:
VBA Code:
Public Stopflag As Boolean
Sub runnum()
Do While Not (Stopflag)
 Range("F4") = Range("f4") + 1
 If Range("f4") > 2000 Then Range("F4") = 0
 ' call your subroutine here instead of the last two lines of code
 DoEvents
Loop

End Sub

Sub Stoprun()
 Stopflag = True
End Sub
Sub Startrun()
Stopflag = False
Call runnum
End Sub
Thank you so much for this, works exactly as needed, saved a lot of head scratching, thank you again!
 
Upvote 0
Hi sorry I have this working, as in it will spin the numbers around as requested, the issue is I cannot get the action to stop, I am not very good with Macros! All I want is for the action to stop once a button is pressed. I have added a demo to explain. Again very much for the actions so far!
 
Upvote 0
Please post the code that you have actually got here , because running the Stoprun macro from a button should stop it, but it does depend on exactly what code you have got in your macro
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top