ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Create a New Random Number Every 2 Seconds (https://www.excelbanter.com/excel-programming/347477-create-new-random-number-every-2-seconds.html)

gatesheadthunde[_3_]

Create a New Random Number Every 2 Seconds
 

Hi,

Just wondering how I can create a whole number between 1 and 10 every 2
seconds for 2 minutes on the press of a button?

The number will paste in to cell A1 and be overwritten every 2 seconds
when a number is generated?

I'm quite new to VBA with Excel so if anyone can recommend some free
easy to understand tutorials, please let me know.

Thanks :)


--
gatesheadthunde
------------------------------------------------------------------------
gatesheadthunde's Profile: http://www.excelforum.com/member.php...o&userid=10536
View this thread: http://www.excelforum.com/showthread...hreadid=491199


JE McGimpsey

Create a New Random Number Every 2 Seconds
 
One way:

Public Sub TwoRandomMinutes()
Static dEnd As Double
If dEnd = 0 Then dEnd = Now() + TimeSerial(0, 2, 0)
If Now <= dEnd Then
Range("A1").Value = Int(Rnd * 10) + 1
Application.OnTime Now() + TimeSerial(0, 0, 2), _
"TwoRandomMinutes"
Else
dEnd = 0
End If
End Sub


In article
<gatesheadthunde.1zmyxb_1133902212.0529@excelfor um-nospam.com,
gatesheadthunde
<gatesheadthunde.1zmyxb_1133902212.0529@excelfor um-nospam.com wrote:

Hi,

Just wondering how I can create a whole number between 1 and 10 every 2
seconds for 2 minutes on the press of a button?

The number will paste in to cell A1 and be overwritten every 2 seconds
when a number is generated?

I'm quite new to VBA with Excel so if anyone can recommend some free
easy to understand tutorials, please let me know.

Thanks :)


Tom Ogilvy

Create a New Random Number Every 2 Seconds
 
See Chip Pearson's page on using Application.Ontime

http://www.cpearson.com/excel/ontime.htm

for starting with code:

http://www.mvps.org/dmcritchie/excel/getstarted.htm


to generate a random number between 1 and 10

Range("B9").Value = int(rnd()*10+1)

--
Regards,
Tom Ogilvy


"gatesheadthunde"
<gatesheadthunde.1zmyxb_1133902212.0529@excelfor um-nospam.com wrote in
message news:gatesheadthunde.1zmyxb_1133902212.0529@excelf orum-nospam.com...

Hi,

Just wondering how I can create a whole number between 1 and 10 every 2
seconds for 2 minutes on the press of a button?

The number will paste in to cell A1 and be overwritten every 2 seconds
when a number is generated?

I'm quite new to VBA with Excel so if anyone can recommend some free
easy to understand tutorials, please let me know.

Thanks :)


--
gatesheadthunde
------------------------------------------------------------------------
gatesheadthunde's Profile:

http://www.excelforum.com/member.php...o&userid=10536
View this thread: http://www.excelforum.com/showthread...hreadid=491199





All times are GMT +1. The time now is 08:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com