How to get random sample in Excel with no duplicates (2023)

The tutorial focuses on how to do random sampling in Excel with no repeats. You will find solutions for Excel 365, Excel 2021, Excel 2019 and earlier versions.

A while ago, we described a few different ways to randomly select in Excel. Most of those solutions rely on the RAND and RANDBETWEEN functions, which may generate duplicate numbers. Consequently, your random sample might contain repeating values. If you need a random selection without duplicates, then use the approaches described in this tutorial.

  • Random selection from list with no duplicates in Excel 365 - 2021
  • How to select random rows with no repeats in Excel 365 - 2021
  • How to do random sampling in Excel 2019 - 2010
  • How to prevent Excel random sample from changing
  • Random selection in Excel 365 - Excel 2010: rows, columns or cells

Excel random selection from list with no duplicates

Only works in Excel 365 and Excel 2021 that support dynamic arrays.

To make a random selection from a list with no repeats, use this generic formula:


Where n is the desired selection size.

For example, to get 5 unique random names from the list in A2:A10, here's the formula to use:


(Video) Excel Formula: How to pick a random sample from a list (no duplicates) - Doctor Excel #018

For the sake of convenience, you can input the sample size in a predefined cell, say C2, and supply the cell reference to the SEQUENCE function:

How to get random sample in Excel with no duplicates (1)

How this formula works:

Here's a high-level explanation of the formula's logic: the RANDARRAY function creates an array of random numbers, SORTBY sorts the original values by those numbers, and INDEX retrieves as many values as specified by SEQUENCE.

A detailed breakdown follows below:

The ROWS function counts how many rows your data set contains and passes the count to the RANDARRAY function, so it can generate the same number of random decimals:


This array of random decimals is used as the "sort by" array by the SORTBY function. As the result, your original data gets shuffled randomly.

From the randomly sorted data, you extract a sample of a specific size. For this, you supply the shuffled array to the INDEX function and request to retrieve the first N values with the help of the SEQUENCE function, which produces a sequence of numbers from 1 to N. Because the original data is already sorted in random order, we do not really care which positions to retrieve, only the quantity matters.

(Video) Create a List of Random Numbers without Repeats

Select random rows in Excel without duplicates

Only works in Excel 365 and Excel 2021 that support dynamic arrays.

To select random rows with no repeats, build a formula in this way:

INDEX(SORTBY(data, RANDARRAY(ROWS(data))), SEQUENCE(n), {1,2,…})

Where n is the sample size and {1,2,…} are column numbers to extract.

As an example, let's select random rows from A2:C10 without duplicate entries, based on the sample size in F1. As our data is in 3 columns, we supply this array constant to the formula: {1,2,3}


And get the following result:
How to get random sample in Excel with no duplicates (2)

How this formula works:

The formula works with exactly the same logic as the previous one. A small change that makes a big difference is that you specify both the row_num and column_num arguments for the INDEX function: row_num is supplied by SEQUENCE and column_num by the array constant.

(Video) Learn Excel 2010 - "Random with No Repeats": Podcast #1471

How to do random sampling in Excel 2010 - 2019

As only Excel for Microsoft 365 and Excel 2021 support dynamic arrays, the dynamic array functions used in the previous examples only work in Excel 365. For other versions, you'll have to work out a different solution.

Supposing you want a random selection from the list in A2:A10. This can be done with 2 separate formulas:

  1. Generate random numbers with the Rand formula. In our case, we enter it in B2, and then copy down to B10:


  2. Extract the first random value with the below formula, which you enter in E2:

    =INDEX($A$2:$A$10, RANK.EQ(B2, $B$2:$B$10) + COUNTIF($B$2:B2, B2) - 1)

  3. Copy the above formula to as many cells as many random values you want to pick. In this example, we want 4 names, so we copy the formula from E2 through E5.

Done! Our random sample without duplicates looks as follows:
How to get random sample in Excel with no duplicates (3)

How this formula works:

Like in the first example, you use the INDEX function to retrieve values from column A based on random row numbers. The difference is in how you get those numbers:

The RAND function fills the range B2:B10 with random decimals.

The RANK.EQ function calculates the rank of a random number in a given row. For example, in E2, RANK.EQ(B2, $B$2:$B$10) ranks the number in B2 against all the numbers in B2:B10. When copied to E3, the relative reference B2 changes to B3 and returns the rank of the number in B3, and so on.

(Video) How to Create Random Numbers in Excel (including no repeats)

The COUNTIF function finds how many occurrences of a given number there are in the above cells. For instance, in E2, COUNTIF($B$2:B2, B2) checks just one cell - B2 itself, and returns 1. In E5, the formula changes to COUNTIF($B$2:B5, B5) and returns 2, because B5 contains the same value as B2 (please note, this is only to better explain the formula's logic; on a small dataset, chances to get duplicate random numbers are close to zero).

As the result, for all 1st occurrences, COUNTIF returns 1, from which you subtract 1 to keep the original ranking. For 2nd occurrences, COUNTIF returns 2. By subtracting 1 you increment the ranking by 1, thus preventing duplicate ranks.

For example, for B2, RANK.EQ returns 1. As this is the first occurrence, COUNTIF also returns 1. RANK.EQ + COUNTIF gives 2. And - 1 restores the rank 1.

Now, see what happens in case of the 2nd occurrence. For B5, RANK.EQ also returns 1 while COUNTIF returns 2. Adding these up gives 3, from which you subtract 1. As the final result, you get 2, which represents the rank of the number in B5.

The rank goes to the row_num argument of the INDEX function, and it picks the value from the corresponding row (the column_num argument is omitted, so it defaults to 1). This is the reason why it is so important to avoid duplicate ranking. If it were not for the COUNTIF function, RANK.EQ would yield 1 for both B2 and B5, causing INDEX to return the value from the first row (Andrew) twice.

How to prevent Excel random sample from changing

As all randomizing functions in Excel such as RAND, RANDBETWEEN and RANDARRAY are volatile, they recalculate with every change on the worksheet. As the result, your random sample will be continuously changing. To prevent this from happening, use the Paste Special > Values feature to replace formulas with static values. For this, carry out these steps:

  1. Select all the cells with your formula (any formula containing RAND, RANDBETWEEN or RANDARRAY function) and press Ctrl + C to copy them.
  2. Right click the selected range and click Paste Special > Values. Alternatively, press Shift + F10 and then V, which is the shortcut for the above-mentioned feature.

For the detailed steps, please see How to convert formulas to values in Excel.

Excel random selection: rows, columns or cells

Works in all versions of Excel 365 through Excel 2010.

If you have our Ultimate Suite installed in your Excel, then you can do random sampling with a mouse click instead of a formula. Here's how:


  1. On the Ablebits Tools tab, click Randomize > Select Randomly.
  2. Select the range from which you want to pick a sample.
  3. On the add-in's pane, do the following:
    • Choose whether you want to select random rows, columns, or cells.
    • Define the sample size: that can be a percentage or number.
    • Click the Select button.

That's it! As shown in the image below, a random sample is selected directly in your data set. If you'd like to copy it somewhere, just press a regular copy shortcut (Ctrl + C).
How to get random sample in Excel with no duplicates (4)

That's how to select a random sample in Excel without duplicates. I thank you for reading and hope to see you on our blog next week!

Available downloads

Random sample without duplicates - formula examples (.xlsx file)
Ultimate Suite 14-day fully-functional version (.exe file)

You may also be interested in

  • How to generate random numbers in Excel
  • How to randomly select in Excel
  • How to sort randomly in Excel
  • RANDARRAY function to generate random numbers in Excel
  • How to prevent duplicates in a column in Excel


How do I make Randbetween not repeat? ›

As both RAND and RANDBETWEEN recalculate with every change on the worksheet, your list of random numbers will be continuously changing. To prevent this from happening, use Paste Special > Values to convert formulas to values as explained in How to stop random numbers from recalculating. Delete duplicates.

How do I find Data in Excel without duplicates? ›

Filter for unique values or remove duplicate values
  1. To filter for unique values, click Data > Sort & Filter > Advanced.
  2. To remove duplicate values, click Data > Data Tools > Remove Duplicates.
  3. To highlight unique or duplicate values, use the Conditional Formatting command in the Style group on the Home tab.

Which can be used to create a random number without duplication? ›

To generate a random array of non-duplicate values, we'll use three dynamic array functions: RANDARRAY(), UNIQUE(), and SEQUENCE().

How do I randomly select a sample in Excel? ›

How to generate a random sample using Excel
  1. Add a new column within the spreadsheet and name it Random_number.
  2. In the first cell underneath your heading row, type “= RAND()”
  3. Press “Enter,” and a random number will appear in the cell.
  4. Copy and paste the first cell into the other cells in this column.

How do I generate unique random numbers in Excel? ›

Here is how you can use the RAND function to generate a set of unique random numbers in Excel:
  1. In a column, use =RAND() formula to generate a set of random numbers between 0 and 1.
  2. Once you have generated the random numbers, convert it into values, so that it won't recalculate again and again to make your workbook slow.

How do I generate a series of random numbers in Excel? ›

If you want to use RAND to generate a random number but don't want the numbers to change every time the cell is calculated, you can enter =RAND() in the formula bar, and then press F9 to change the formula to a random number. The formula will calculate and leave you with just a value.


1. How to Create a Random Sample in Excel (in 3 minutes!)
(Check Your Assumptions)
2. Unique Random Number Generator in Excel - No Duplicates | Randomly Select Names in Excel
(Chester Tugwell)
3. Excel formula to Pick 3 random values from a list [without Duplicates]
(Ajay Anand)
4. How To Create A Random Sample In Excel (2 Methods!)
(Top Tip Bio)
5. Excel Magic Trick 302: Randomly Select Names No Repeats
6. ExcelLearn !! How to Generate Random Numbers/Data List without duplicate + Sampling In Excel Hindi!!
Top Articles
Latest Posts
Article information

Author: Greg Kuvalis

Last Updated: 28/03/2023

Views: 5816

Rating: 4.4 / 5 (75 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Greg Kuvalis

Birthday: 1996-12-20

Address: 53157 Trantow Inlet, Townemouth, FL 92564-0267

Phone: +68218650356656

Job: IT Representative

Hobby: Knitting, Amateur radio, Skiing, Running, Mountain biking, Slacklining, Electronics

Introduction: My name is Greg Kuvalis, I am a witty, spotless, beautiful, charming, delightful, thankful, beautiful person who loves writing and wants to share my knowledge and understanding with you.