+ Reply to Thread
Results 1 to 4 of 4

generate random numbers for each ID in column A

  1. #1
    Registered User
    Join Date
    09-20-2019
    Location
    lebanon
    MS-Off Ver
    2016
    Posts
    36

    generate random numbers for each ID in column A

    I'm trying to generate 17 numbers from (81 to 98) in column B random not duplicate (at least generate 2 to 17) for each equal number in A column , I have this code but I want to write it better than this
    Please Login or Register  to view this content.
    the output that I need sth like this table:
    Please Login or Register  to view this content.
    the output in this sheet
    Attached Files Attached Files
    Last edited by fatoom91; 08-16-2020 at 03:33 PM.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,811

    Re: generate random numbers for each ID in column A

    I would use a shuffle rather than randbetween() for this. In the spreadsheet or VBA, I would:

    1) Generate 18 unique random numbers (RAND() function in the spreadsheet, Rnd() function in VBA. Don't forget to use the Randomize statement so that VBA's random number generator will be random (or at least random enough).
    2) Use MATCH() and SMALL() [or LARGE()] to find the random numbers from largest to smallest =MATCH(SMALL(random_numbers,1),random_numbers,0) for example. This will return the row #/column #/cell #/array index # for the smallest ith number. Repeat for i = 1 to 18
    3) You should now have the numbers 1 to 18 shuffled into a random order. Now add 80 to each to get the numbers 81 to 98 in random order. Take the first 17 of these numbers.

    I don't know if you are required or just prefer VBA -- I usually prefer to do this in the spreadsheet without VBA. Whichever programming language you prefer, try that process and see if it works for you.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Registered User
    Join Date
    09-20-2019
    Location
    lebanon
    MS-Off Ver
    2016
    Posts
    36
    Thanks for your answer MrShortly but I need it with vba code ..
    The code (if a>32 or 45 )or any number smaller than 50 cannot generate exactly the count of numbers that I want
    Last edited by fatoom91; 08-17-2020 at 09:44 AM.

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,811

    Re: generate random numbers for each ID in column A

    The instructions I gave should work in any programming language. What part of translating that into VBA are you having trouble with? I would expect something like
    Please Login or Register  to view this content.

+ 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] generate random numbers in random range vba
    By hsnfifo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-20-2020, 12:59 PM
  2. [SOLVED] Generate random lines 3 numbers limit per line and 3 per column The matrix below 5x5
    By jorel in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-24-2016, 07:18 PM
  3. [SOLVED] How to generate non-repeating random numbers in a column wihtout VB
    By luv2glyd in forum Excel General
    Replies: 4
    Last Post: 02-16-2015, 12:43 AM
  4. Replies: 8
    Last Post: 11-18-2013, 04:24 PM
  5. [SOLVED] Generate Random numbers where sum = 1
    By sajeel in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-18-2013, 07:12 AM
  6. [SOLVED] Generate Random Numbers
    By stojko89 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-09-2013, 02:49 AM
  7. generate random numbers
    By fo05kka in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-08-2009, 09:55 PM

Tags for this Thread

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