Results 1 to 3 of 3

Working with random numbers

Threaded View

  1. #1
    Registered User
    Join Date
    03-06-2010
    Location
    Louisiana
    MS-Off Ver
    Excel 2007
    Posts
    1

    Question Working with random numbers

    Ok so:

    I am trying to create a row of randomly chosen integers between 1 and 9... however there is a catch... a number must not be repeated. Here's what I've come up with so far:

    Public Sub RandomSpot()

    Rem Introduce a nrandom integer 1-9 into cell (1,1)
    Rem "Rnd()*10" creates a random number from 0 to 1 then multiplies by 10
    Rem to get a random number from 0 to 10.
    Rem The INT command truncates decimals, creating an Integer.
    Rem Since there is a chance that number will be either a 0 or a 10,
    Rem I have the computer recalculate a number until a number between 1 and 9 is chosen

    Do until 1 <= Sheet1.cells(1,1) <=9
    Sheet1.Cells(1,1)=INT(Rnd()*10)
    Loop


    Rem Now, I wish to create numbers in the remaining columns of row 1
    Rem however, they cannot be the same as the value in any other column.

    ""This is where I get stuck... what type of loop would this be? And how would I tell the computer to verify the next number's uniquness?


    Basically I am trying to program a loop which will place a number 1-9 in the adjacent columns, but first it checks the other cells in the row to ensure that the number hasn't already been used.

    As it stands, my code is sometimes producing the same number in a row.

    I am not sure of the error.

    Please help

    -Jeff
    Last edited by Jnels23; 03-06-2010 at 07:55 PM.

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