Extract sample randomly in Excel

Last Updated on 05/11/2024
Reading time: 2 minutes

The sample random selection of your data can be done easily with the INDIRECT function.

You have a file with 19,000 rows. Each row has customer information: address, city, and country. You need to mail a coupon to 30 clients. To select customers randomly, follow these steps:

Customer Database in a workbook

Step 1: Create a List of Random Numbers

First, create a list of 30 random numbers. You have two Excel functions for this:

  1. RANDBETWEEN(min_value, max_value)
  2. RANDARRAY(rows, columns, min, max, integer)

Both functions give random numbers between min and max values. RANDARRAY returns multiple numbers based on the row argument.

Generate a list of random numbers with RANDBETWEEN

Convert the random number result to values to avoid regeneration. Copy and paste as values after creating random numbers. See this demo:

Paste in value

Step 2: Point to a Cell in Your Database

Next, write a formula to point to row 2’s LastName value.

Create a relationship to the first lastname

We want the formula to return data from a random row, like row 16,308.

Step 3: Customize Your Cell Reference

Combine the reference of column B with a row number generated by RANDBETWEEN. Use the INDIRECT function:

  1. Write the INDIRECT function.
  2. Keep the column reference in double-quotes.
  3. Use the & sign.
  4. Select the cell with the random number.
Return a name randomly with INDIRECT

To return a country value, change the column reference. In this example, use column F.

Formula to return the country with a random value

Tutorial Video

If you need further help to extract sample randomly, check out the following video:

2 Comments

  1. Rick Rothstein
    03/06/2022 @ 02:32

    May I suggest instead of using the Volatile INDIRECT function as you did with this..

    =INDIRECT("H"&J2)

    to use the non-Volatile INDEX function like this instead...

    =INDEX(H:H,J2)

    Reply

    • Frédéric LE GUEN
      05/06/2022 @ 21:47

      Very good point Rick

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Extract sample randomly in Excel

Reading time: 2 minutes
Last Updated on 05/11/2024

The sample random selection of your data can be done easily with the INDIRECT function.

You have a file with 19,000 rows. Each row has customer information: address, city, and country. You need to mail a coupon to 30 clients. To select customers randomly, follow these steps:

Customer Database in a workbook

Step 1: Create a List of Random Numbers

First, create a list of 30 random numbers. You have two Excel functions for this:

  1. RANDBETWEEN(min_value, max_value)
  2. RANDARRAY(rows, columns, min, max, integer)

Both functions give random numbers between min and max values. RANDARRAY returns multiple numbers based on the row argument.

Generate a list of random numbers with RANDBETWEEN

Convert the random number result to values to avoid regeneration. Copy and paste as values after creating random numbers. See this demo:

Paste in value

Step 2: Point to a Cell in Your Database

Next, write a formula to point to row 2’s LastName value.

Create a relationship to the first lastname

We want the formula to return data from a random row, like row 16,308.

Step 3: Customize Your Cell Reference

Combine the reference of column B with a row number generated by RANDBETWEEN. Use the INDIRECT function:

  1. Write the INDIRECT function.
  2. Keep the column reference in double-quotes.
  3. Use the & sign.
  4. Select the cell with the random number.
Return a name randomly with INDIRECT

To return a country value, change the column reference. In this example, use column F.

Formula to return the country with a random value

Tutorial Video

If you need further help to extract sample randomly, check out the following video:

2 Comments

  1. Rick Rothstein
    03/06/2022 @ 02:32

    May I suggest instead of using the Volatile INDIRECT function as you did with this..

    =INDIRECT("H"&J2)

    to use the non-Volatile INDEX function like this instead...

    =INDEX(H:H,J2)

    Reply

    • Frédéric LE GUEN
      05/06/2022 @ 21:47

      Very good point Rick

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *