Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default 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 :)

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I create a random number generator in excel? Katie Excel Worksheet Functions 2 July 20th 06 01:50 AM
Create a Graph with Random Number Generator Luke Williams Charts and Charting in Excel 9 December 19th 05 06:42 PM
Can excel be used to create a random number generator? comotoman Excel Discussion (Misc queries) 2 September 16th 05 09:55 PM
Create random number bingo cards with Excel teachertolawyer New Users to Excel 5 September 15th 05 11:34 AM
How do you create a random number generator in Excel? gmrobillard Excel Worksheet Functions 5 March 23rd 05 09:10 AM


All times are GMT +1. The time now is 12:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"