Results 1 to 4 of 4
  • Thread Tools
  1. Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    6 Unique Random Numbers (XP; SP3)

    How would one control the random number to only return six unique values?

    The code I have been toying with generates duplicate values:

    Sub RandomNumbers_6_Unique()
    oNo1 = Int((6 * Rnd) +1)
    oNo2 = Int((6 * Rnd) +1)
    oNo3 = Int((6 * Rnd) +1)
    oNo4 = Int((6 * Rnd) +1)
    oNo5 = Int((6 * Rnd) +1)
    oNo6 = Int((6 * Rnd) +1)

    MsgBox oNo1 & "-" & oNo2 & "-" & oNo3 & "-" & oNo4 & "-" & oNo5 & "-" & oNo6

    End Sub


    This is a test to return only numbers between 1 and 6. Eventually I will expand it and only want 6 unique random numbers returned.

    Thanks,
    John

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. 3 Star Lounger
    Join Date
    Dec 2001
    Location
    Doorn, Netherlands
    Posts
    311
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 6 Unique Random Numbers (XP; SP3)

    Get yourself the freeware morefunc(tions) addin from

    http://longre.free.fr

    Regards,
    Teunis

  4. Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 6 Unique Random Numbers (XP; SP3)

    I think you will have to use VBA to do this. Does this <post#=222,852>post 222,852</post: > give you enough to do what you want?
    Legare Coleman

  5. 3 Star Lounger
    Join Date
    Dec 2001
    Location
    Doorn, Netherlands
    Posts
    311
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 6 Unique Random Numbers (XP; SP3)

    Link made clickable by HansV

    Sorry,

    The morefunc site was updated to

    http://xcell05.free.fr/

    Regards,
    Teunis

Posting Permissions

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