+ Reply to Thread
Results 1 to 9 of 9

Random selection from a column of data

  1. #1
    Forum Contributor
    Join Date
    06-29-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2016 (Office 365)
    Posts
    137

    Random selection from a column of data

    Hi all,

    I have a column of about 120,000 numbers (A2:A120000) and would like to randomly select about 1200 of these numbers and place them in column b (B2:B1200) using VBA, any suggestions?

    Cheers,
    Marcus

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Random selection from a column of data

    Try this in B2 then drag down to B1200
    Please Login or Register  to view this content.
    Replace 1 with the lowest # in column A and 50 with the highest # in column A

    This may only work if your numbers in column A do not skip.

    This might work better for you
    Please Login or Register  to view this content.
    Last edited by gmr4evr1; 05-25-2015 at 01:02 PM. Reason: Added alternative
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  3. #3
    Forum Contributor
    Join Date
    07-25-2012
    Location
    Winterville, NC
    MS-Off Ver
    Excel 2013
    Posts
    141

    Re: Random selection from a column of data

    Are there any duplicates in your list? Are you ok with having duplicates in the randomly selected list of 1200? The answers to those questions may impact the responses you get.

  4. #4
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2404
    Posts
    13,407

    Re: Random selection from a column of data

    Withdrawn by FR.
    Last edited by FlameRetired; 05-25-2015 at 07:20 PM.

  5. #5
    Forum Contributor
    Join Date
    06-29-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2016 (Office 365)
    Posts
    137

    Re: Random selection from a column of data

    Hi all,

    gmr - I was thinking about using randombetween however what I need is a subset of the actual 120,000 numbers. The min is 0.75 and max 771 with a mean of 4.5 so I don't think Randbetween will work for me as it wont give me an accurate representation of the data.

    acroley1 - yes there are duplicates and I am happy to have duplicates in the subset.

    To further explain the 1200 number, this is random and depends on how many values are in a third column. So I need to do something like:

    do while "third column" <> ""

    randomly select a number from column A and place it in column B

    loop

    Cheers,
    Marcus

  6. #6
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Random selection from a column of data

    I entered in Column A the values from 1 to 120,000

    In Column B I used RANDBETWEEN(1,100,000,000) Then copied the range and pasted Values to get rid of the formula

    In Column C I entered this to rank all the values in Column B without having ties:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    In Column H I entered this to get the 1200 smallest values:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    In Column G I entered this to get the corresponding values
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    This is long and involved but returned 1200 random unique values.
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  7. #7
    Forum Contributor
    Join Date
    06-29-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2016 (Office 365)
    Posts
    137

    Re: Random selection from a column of data

    Thanks for the suggestion newdoverman but sleeping on it obviously helped and I cracked it with this:

    Please Login or Register  to view this content.
    Probably would have helped if I attached the worksheet with the actual information on it in the first place to help with my explanation.

    Thanks all who replied.

    Cheers,
    Marcus

  8. #8
    Forum Contributor
    Join Date
    06-29-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2016 (Office 365)
    Posts
    137

    Re: Random selection from a column of data

    and I just spotted the obvious error and changed the false to a true!

  9. #9
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Random selection from a column of data

    Glad you got it figured out and thanks for the rep.

+ 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 selection of rows for each unique value in a column
    By tin0989 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-18-2012, 10:36 AM
  2. Replies: 10
    Last Post: 12-21-2010, 06:14 PM
  3. Random selection with multiple column criteria
    By kleick in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-03-2009, 03:50 PM
  4. Replies: 4
    Last Post: 02-06-2009, 11:18 PM
  5. random data selection
    By Miloud in forum Excel General
    Replies: 3
    Last Post: 01-14-2009, 02:07 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