+ Reply to Thread
Results 1 to 9 of 9

Generate unique random numbers within range and input in desired cell

  1. #1
    Registered User
    Join Date
    04-20-2015
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    9

    Generate unique random numbers within range and input in desired cell

    Hello,

    I need help in a macro which allows me to generate 24 non-repeating numbers within a range that i will specify in vba, and than appear in selected cells.

    For eg.
    Range 1200 to 1300
    Numbers to appear in cell A1:A4, B1:B4, and so forth

    I tried finding all over the web but it only provides the ones where an input box will appear to specify the range i want when the macro is run.

    Thanks in advance!

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this ‼


    PHP Code: 
     Sub Demo()
        
    Dim Rg As Range
        Randomize

        With 
    [A1:D6]
            .
    Clear
        
            
    For N% = 1 To .Count
                
    Do
                           
    V% = Fix(Rnd 101) + 1200
                       Set Rg 
    = .Find(V)
                        If 
    Rg Is Nothing Then .Cells(N).Value V
                Loop Until Rg Is Nothing
            Next
        End With
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 04-30-2015 at 01:16 PM.

  3. #3
    Registered User
    Join Date
    04-20-2015
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    9

    Re: Hi ! Try this ‼

    Yeahhhh that's was what i was looking for! Thanks alot. Anyway if i want to change to range between 1300 to 1500, how do i do that?

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,552

    Re: Generate unique random numbers within range and input in desired cell

    Try this
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-20-2015
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    9

    Re: Generate unique random numbers within range and input in desired cell

    Thanks for your reply!

    But is there anyway i can do it without the input box? Like key in the range straight in the code itself?

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,552

    Re: Generate unique random numbers within range and input in desired cell

    Then change inputboxes part to the numbers you want.

    Don't really understand what you are trying to say though.

  7. #7
    Registered User
    Join Date
    04-20-2015
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    9

    Re: Generate unique random numbers within range and input in desired cell

    I meant like you specify the range of numbers within the code so that it will generate automatically instead of when I run the macro, an input box will pop up and i have to key in the range everytime.

    But thanks anyway!

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,552

    Re: Generate unique random numbers within range and input in desired cell

    Quote Originally Posted by jindon View Post
    Then change inputboxes part to the numbers you want.
    i.e
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    04-20-2015
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    9

    Re: Generate unique random numbers within range and input in desired cell

    Oh alright! Thank you!

+ 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. Replies: 20
    Last Post: 09-27-2019, 10:11 AM
  2. [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
  3. Formula to generate unique random numbers?!?
    By aims in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-07-2013, 03:14 PM
  4. Generate random non-repeated range of numbers?
    By satoshi in forum Excel General
    Replies: 2
    Last Post: 06-17-2009, 05:32 AM
  5. [SOLVED] generate unique random numbers
    By Stephen Larivee in forum Excel - New Users/Basics
    Replies: 7
    Last Post: 03-28-2006, 08:10 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