+ Reply to Thread
Results 1 to 3 of 3

Set 10 cells to different random numbers

  1. #1
    Registered User
    Join Date
    12-20-2005
    Posts
    69

    Set 10 cells to different random numbers

    Hi, I need some code so that when I press a button, the ten cells above are each given a random number between 1 and 10. However, I need to ensure that they are all different so none are repeated. How do I do this? So far I have written the following, although obviously this doesn't ensure that all numbers are different:

    Please Login or Register  to view this content.
    Last edited by dominicb; 09-23-2008 at 07:01 AM.

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good afternoon krabople
    Quote Originally Posted by krabople View Post
    Hi, I need some code so that when I press a button, the ten cells above are each given a random number between 1 and 10. So far I have written the following, although obviously this doesn't ensure that all numbers are different
    Next time you post code, please remember to use code tags (the little "#" button). I've done it for you on this occasion.

    The best way I have found to do this is put all the numbers into an array and check each time one is added that the number isn't already there - if it is, loop back and do it again.

    This code should work OK :
    Please Login or Register  to view this content.
    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  3. #3
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264
    Here's another way of doing it which randomizes each element's position rather than the actual value of each element:

    Please Login or Register  to view this content.
    Richard

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. random numbers with a probability
    By caldera55 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-19-2008, 05:11 PM
  2. cells random sorting
    By patje in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-08-2007, 05:30 AM
  3. Combining 2 cells numbers unless one doesn't exist
    By desk.doc in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-11-2007, 03:24 PM
  4. Selecting random cells using certain criteria
    By tcpace in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-23-2007, 11:50 AM
  5. Find, return string address in a range of cells with numbers and text
    By Vera22 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-09-2007, 08:37 PM

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