+ Reply to Thread
Results 1 to 2 of 2

Recording incidences of results of a RAND() fucntion.

  1. #1
    Registered User
    Join Date
    10-02-2003
    Location
    East Midlands, UK
    MS-Off Ver
    MS Office Professional Plus 2016
    Posts
    40

    Question Recording incidences of results of a RAND() function.

    I have a random function which generates an integer from 1-9 with each screen refresh.

    Would I be able to tally how many times each number was generated? What I imagined was setting up an additional COL 'Results' and then trying to increment an

    if [Cell Ref of Rand Function]=1 then x (cell containing tally of incidence of result 1) =x+1

    if [Cell Ref of Rand Function]=2 then x (cell containing tally of incidence of result 2) =x+1
    etc. etc.

    style argument. Thus I could see how often a number was picked by the RAND.

    Is this possible, and how might I do it? Any comments gratefully received.

    Thanks for looking!

    Baldy
    Last edited by BaldySlaphead; 07-15-2005 at 04:44 AM. Reason: spelling error

  2. #2
    Dave Peterson
    Guest

    Re: Recording incidences of results of a RAND() fucntion.

    You could use a worksheet event that checks that cell after every recalculation,
    but that seems like you could lose control pretty quickly (excel can recalculate
    lots of times and you may not be prepared for that).

    I think I would use a dedicated macro.

    I put =randbetween(1,10) in A1 (I had to have the analysis pack addin loaded)

    Then I had used this macro to count the results.

    Option Explicit
    Sub testme()

    Dim myCell As Range
    Dim myRng As Range
    Dim iCtr As Long
    Dim MaxTimes As Long

    MaxTimes = 10

    With Worksheets("Sheet1")
    Set myCell = .Range("a1")
    Set myRng = .Range("b1:B10") '<- ten cells!

    myRng.ClearContents 'start new each time?
    For iCtr = 1 To MaxTimes
    Application.Calculate
    myRng(myCell.Value) = myRng(myCell.Value) + 1
    Next iCtr
    End With

    End Sub

    If calculation is set to automatic, just incrementing the cell causes a recalc.

    If you're new to macros, you may want to read David McRitchie's intro at:
    http://www.mvps.org/dmcritchie/excel/getstarted.htm

    BaldySlaphead wrote:
    >
    > I have a random function which generates an integer from 1-9 with each
    > screen refresh.
    >
    > Would I be able to tally how many times each number was generated? What
    > I imagined was setting up an additional COL 'Results' and then trying to
    > increment an
    >
    > -if [Cell Ref of Rand Function]=1 then x (cell containing tally of
    > incidence of result 1) =x+1
    >
    > if [Cell Ref of Rand Function]=2 then x (cell containing tally of
    > incidence of result 2) =x+1 - etc. etc.
    >
    > style argument. Thus I could see how often a number was picked by the
    > RAND.
    >
    > Is this possible, and how might I do it? Any comments gratefully
    > received.
    >
    > Thanks for looking!
    >
    > Baldy
    >
    > --
    > BaldySlaphead
    > ------------------------------------------------------------------------
    > BaldySlaphead's Profile: http://www.excelforum.com/member.php...fo&userid=1260
    > View this thread: http://www.excelforum.com/showthread...hreadid=387444


    --

    Dave Peterson

+ 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