+ Reply to Thread
Results 1 to 3 of 3

excel random sample with criterion

  1. #1
    gilgamesh2006
    Guest

    excel random sample with criterion

    I need to create a macro or function that will pull a random sample from
    column B, but only when the criterion in column A is met. For example:
    Column A Column B
    A 123
    A 456
    A 789
    B 234

    I need to pull a random sample of the values in column b, but need the
    ability to select the column A value. I was hoping for a button or formula
    that i could move from sheet to sheet since we get a system generated list
    each week.

  2. #2
    Gary''s Student
    Guest

    RE: excel random sample with criterion

    Here is a neat trick:

    The usual technique is to put =RAND() down column C and then sort by column
    C. This will shuffle cols A & B. Instead put:

    =(A1="A")*100 + RAND() in C1 and copy down. Now each sort (descending) will
    put all the "A"'s at the top in a random order.

    Just keep picking B1 after each sort.
    --
    Gary's Student


    "gilgamesh2006" wrote:

    > I need to create a macro or function that will pull a random sample from
    > column B, but only when the criterion in column A is met. For example:
    > Column A Column B
    > A 123
    > A 456
    > A 789
    > B 234
    >
    > I need to pull a random sample of the values in column b, but need the
    > ability to select the column A value. I was hoping for a button or formula
    > that i could move from sheet to sheet since we get a system generated list
    > each week.


  3. #3
    vezerid
    Guest

    Re: excel random sample with criterion

    Hi, if you only need to select one of the numbers in B:B, the following
    *array* formula might also work for you (assuming data in A2:B8):

    =SMALL(IF(A2:A8="A",B2:B8),INT(RAND()*COUNTIF(A2:A8,"A"))+1)

    As an array formula it must be entered with the key combination
    Shift+Ctrl+Enter.

    HTH
    Kostis Vezerides


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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