Create a New Random Number Every 2 Seconds

  • Thread starter gatesheadthunde
  • Start date
G

gatesheadthunde

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 :)
 
J

JE McGimpsey

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


gatesheadthunde
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top