+ Reply to Thread
Results 1 to 3 of 3

Create a New Random Number Every 2 Seconds

  1. #1
    Registered User
    Join Date
    06-11-2004
    Posts
    1

    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

  2. #2
    JE McGimpsey
    Guest

    Re: 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@excelforum-nospam.com>,
    gatesheadthunde
    <gatesheadthunde.1zmyxb_1133902212.0529@excelforum-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. #3
    Tom Ogilvy
    Guest

    Re: 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@excelforum-nospam.com> wrote in
    message news:gatesheadthunde.1zmyxb_1133902212.0529@excelforum-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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1