+ Reply to Thread
Results 1 to 6 of 6

Unique random numbers from a range of numbers

  1. #1
    Registered User
    Join Date
    04-07-2021
    Location
    Maastricht, Netherlands
    MS-Off Ver
    365
    Posts
    59

    Question Unique random numbers from a range of numbers

    Hello all,

    Maybe some one could help me with this code.
    I would like to pick 25 unique random numbers from a column and give them a color
    the code below does that but it also picks also duplicates and that's something I don't want.
    Is there a code that prevents getting duplicates?


    Dim randomNum As Long

    For Rcounter = 1 To 25 'door het cijfer aan te passen verander je de aantallen die willekeurig worden gekozen
    randomNum = WorksheetFunction.RandBetween(StartRow, LastRow)
    Cells(randomNum, ColumnD).Interior.Color = RGB(255, 207, 153)
    Cells(randomNum, ColumnD).Select
    Next Rcounter



    Thanks in advance for your help,
    RV

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: Unique random numbers from a range of numbers

    staying close to the original code you could try:
    Please Login or Register  to view this content.
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    04-07-2021
    Location
    Maastricht, Netherlands
    MS-Off Ver
    365
    Posts
    59

    Re: Unique random numbers from a range of numbers

    Hello Kaper,

    This works perfect, thank you very much
    a complete other approach then I was thinking, thumbs up

    Have a nice day,
    RV

  4. #4
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Unique random numbers from a range of numbers

    posted in error
    Last edited by davsth; 09-01-2021 at 04:40 AM. Reason: posted in the wrong place

  5. #5
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: Unique random numbers from a range of numbers

    Well, the approach is almost the same as yours.
    Only the loop is "conditional"
    With For...Next loop you advance a loop counter always when the loop content is executed.
    In Do...Loop you can advance counter only when some condition (like random draw of empty cell) is met.

    If (I think so) the solution fits your needs, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  6. #6
    Registered User
    Join Date
    04-07-2021
    Location
    Maastricht, Netherlands
    MS-Off Ver
    365
    Posts
    59

    Re: Unique random numbers from a range of numbers

    again, thanks...

+ 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. [SOLVED] Unique random numbers between two numbers
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-19-2015, 05:51 PM
  2. Generate unique random numbers within range and input in desired cell
    By acronymm in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-04-2015, 03:44 AM
  3. Random unique numbers
    By Peidus in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-23-2014, 01:34 PM
  4. [SOLVED] how to generate random numbers in range 1:20 with unique results
    By jmac1947 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-23-2014, 08:54 AM
  5. Unique random numbers
    By Bartlett in forum Excel General
    Replies: 2
    Last Post: 01-28-2012, 03:42 PM
  6. random unique numbers
    By Juli in forum Excel General
    Replies: 2
    Last Post: 05-05-2011, 05:48 PM
  7. [SOLVED] Unique RANDOM NUMBERS within specified range
    By Matt D Francis in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-09-2006, 09:40 AM

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