Results 1 to 6 of 6

IF statement to evaluate result of random number generator to generate next random number

Threaded View

  1. #1
    Registered User
    Join Date
    05-21-2013
    Location
    Cape Town
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    9

    Question IF statement to evaluate result of random number generator to generate next random number

    I need to scan for random account numbers through a sheet containing account numbers and their details. I have used the following formula to do this:

    Formula: copy to clipboard
    =INDEX(RETRENCHMENT!A:A,RANDBETWEEN(2,COUNTA(RETRENCHMENT!A:A)),1)


    The catch is that column A of the sheet, which contains the account numbers, also contains blank cells between account numbers, and the account numbers are not evenly spaced from each other, and I require the formula to return only account numbers and not blank cells.

    My solution to this has been to try to evaluate the result of the INDEX-RANDBETWEEN formula above using an IF statement in order to decide whether I want to try run the formula again so that I can get a different result.

    I have used:

    Formula: copy to clipboard
    =IF(INDEX(RETRENCHMENT!A:A,RANDBETWEEN(2,COUNTA(RETRENCHMENT!A:A)),1)="",IF(INDEX(RETRENCHMENT!A:A,RANDBETWEEN(3,COUNTA(RETRENCHMENT!A:A)),1),IF(INDEX(RETRENCHMENT!A:A,RANDBETWEEN(2,COUNTA(RETRENCHMENT!A:A)),1))


    In the THEN condition of the IF statement I changed the RANDBETWEEN range to start on the third row to try and "force" a new random process from occuring (not sure if this is necessary). I have gone on to nest this process as far as probabilistically sufficient in my mind but the formula seems still to return a disproportionate number of blank results, leading me to believe that nesting these functions like this does not force Excel to try a different random cell on the RETRENCHMENT sheet.

    My end result of nesting was this:

    Formula: copy to clipboard
    =IF(INDEX(RETRENCHMENT!A:A,RANDBETWEEN(2,COUNTA(RETRENCHMENT!A:A)),1)="",IF(INDEX(RETRENCHMENT!A:A,RANDBETWEEN(3,COUNTA(RETRENCHMENT!A:A)),1)="",IF(INDEX(RETRENCHMENT!A:A,RANDBETWEEN(4,COUNTA(RETRENCHMENT!A:A)),1)="",IF(INDEX(RETRENCHMENT!A:A,RANDBETWEEN(6,COUNTA(RETRENCHMENT!A:A)),1)="",IF(INDEX(RETRENCHMENT!A:A,RANDBETWEEN(6,COUNTA(RETRENCHMENT!A:A)),1)="",IF(INDEX(RETRENCHMENT!A:A,RANDBETWEEN(7,COUNTA(RETRENCHMENT!A:A)),1)="",IF(INDEX(RETRENCHMENT!A:A,RANDBETWEEN(8,COUNTA(RETRENCHMENT!A:A)),1)="",IF(INDEX(RETRENCHMENT!A:A,RANDBETWEEN(9,COUNTA(RETRENCHMENT!A:A)),1)="",IF(INDEX(RETRENCHMENT!A:A,RANDBETWEEN(10,COUNTA(RETRENCHMENT!A:A)),1)="",IF(INDEX(RETRENCHMENT!A:A,RANDBETWEEN(11,COUNTA(RETRENCHMENT!A:A)),1)="",INDEX(RETRENCHMENT!A:A,RANDBETWEEN(12,COUNTA(RETRENCHMENT!A:A)),1),INDEX(RETRENCHMENT!A:A,RANDBETWEEN(11,COUNTA(RETRENCHMENT!A:A)),1)),INDEX(RETRENCHMENT!A:A,RANDBETWEEN(10,COUNTA(RETRENCHMENT!A:A)),1)),INDEX(RETRENCHMENT!A:A,RANDBETWEEN(9,COUNTA(RETRENCHMENT!A:A)),1)),INDEX(RETRENCHMENT!A:A,RANDBETWEEN(8,COUNTA(RETRENCHMENT!A:A)),1)),INDEX(RETRENCHMENT!A:A,RANDBETWEEN(7,COUNTA(RETRENCHMENT!A:A)),1)),INDEX(RETRENCHMENT!A:A,RANDBETWEEN(6,COUNTA(RETRENCHMENT!A:A)),1)),INDEX(RETRENCHMENT!A:A,RANDBETWEEN(5,COUNTA(RETRENCHMENT!A:A)),1)),INDEX(RETRENCHMENT!A:A,RANDBETWEEN(4,COUNTA(RETRENCHMENT!A:A)),1)),INDEX(RETRENCHMENT!A:A,RANDBETWEEN(3,COUNTA(RETRENCHMENT!A:A)),1)),INDEX(RETRENCHMENT!A:A,RANDBETWEEN(2,COUNTA(RETRENCHMENT!A:A)),1))


    Is there a more efficient way (and that works) of letting Excel perform a random number generation, having it evaluate the result of this process and then based on this result either return the result or re-run the random number generation to return a different result?
    Last edited by captive; 06-20-2013 at 09:16 AM. Reason: FORMULA tags

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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