This tutorial will teach you a few quick ways to randomly select names, numbers or any other data. You will also learn how to get a random sample without duplicates and how to randomly select a specified number or percentage of cells, rows or columns in a mouse click.
Whether you do market research for a new product launch or evaluating the results of your marketing campaign, it is important that you use an unbiased sample of data for your analysis. And the easiest way to achieve this is to get random selection in Excel.
What is random sample?
Before discussing sampling techniques, let's provide a bit of background information about random selection and when you might want to use it.
In probability theory and statistics, a random sample is a subset of data selected from a larger data set, aka population. Each element of a random sample is chosen entirely by chance and has an equal probability of being selected. Why would you need one? Basically, to get a non-biased representation of the total population.
For example, you want to conduct a little survey among your customers. Obviously, it would be unwise to send out a questionnaire to each single person in your multi-thousand database. So, whom do your survey? Will that be 100 newest customers, or the first 100 customers listed alphabetically, or 100 people with the shortest names? None of these approaches fit your needs because they are innately biased. To get an impartial sample where everyone carries an equal opportunity of being chosen, do a random selection by using one of the methods described below.
Excel random selection with formulas
There's no built-in function to randomly pick cells in Excel, but you can use one of the functions to generate random numbers as a workaround. These probably cannot be called simple intuitive formulas, but they do work.
How to select a random value from a list
Supposing you have a list of names in cells A2:A10 and you want to randomly select one name from the list. This can be done by using one of the following formulas:
=INDEX($A$2:$A$10,RANDBETWEEN(1,COUNTA($A$2:$A$10)),1)
or
=INDEX($A$2:$A$10,RANDBETWEEN(1,ROWS($A$2:$A$10)),1)
That's it! Your random name picker for Excel is all set up and ready to serve:
Note. Please be aware that RANDBETWEEN is a volatile function, meaning it will recalculate with every change you make to the worksheet. As the result, your random selection will also change. To prevent this from happening, you can copy the extracted name and paste it as value to another cell (Paste Special > Values). For the detailed instructions, please see How to replace formulas with values.
Naturally, these formulas can not only pick random names, but also select random numbers, dates, or any other random cells.
How these formulas work
In a nutshell, you use the INDEX function to extract a value from the list based on a random row number returned by RANDBETWEEN.
More specifically, the RANDBETWEEN function generates a random integer between the two values you specify. For the lower value, you supply the number 1. For the upper value, you use either COUNTA or ROWS to get the total row count. As the result, RANDBETWEEN returns a random number between 1 and the total count of rows in your dataset. This number goes to the row_num argument of the INDEX function telling it which row to pick. For the column_num argument, we use 1 since we want to extract a value from the first column.
Note. This method works well for selecting one random cell from a list. If your sample is supposed to include several cells, the above formula may return several occurrences of the same value because the RANDBETWEEN function is not duplicate-free. It is especially the case when you are picking a relatively big sample from a relatively small list. The next example shows how to do random selection in Excel without duplicates.
How to randomly select in Excel without duplicates
There are a few ways to select random data without duplicates in Excel. Generally, you'd use the RAND function to assign a random number to each cell, and then you pick a few cells by using an Index Rank formula.
With the list of names in cells A2:A16, please follow these steps to extract a few random names:
- Enter the Rand formula in B2, and copy it down the column:
=RAND()
- Put the below formula in C2 to extract a random value from column A:
=INDEX($A$2:$A$16, RANK(B2,$B$2:$B$16), 1)
- Copy the above formula to as many cells as many random values you want to pick. In our case, we copy the formula to four more cells (C2:C6).
That's it! Five random names are extracted without duplicates:
How this formula works
Like in the previous example, you use the INDEX function to extract a value from column A based on a random row coordinate. In this case, it takes two different functions to get it:
- The RAND formula populates column B with random numbers.
- The RANK function returns the rank a random number in the same row. For example, RANK(B2,$B$2:$B$16) in cell C2 gets the rank of the number in B2. When copied to C3, the relative reference B2 changes to B3 and returns the rank of the number in B3, and so on.
- The number returned by RANK is fed to the row_num argument of the INDEX function, so it picks the value from that row. In the column_num argument, you supply 1 because you want to extract a value from the first column.
A word of caution! As shown in the screenshot above, our Excel random selection contains only unique values. But theoretically, there is a slim chance of duplicates appearing in your sample. Here's why: on a very large dataset, RAND might generate duplicate random numbers, and RANK will return the same rank for those numbers. Personally, I've never got any duplicates during my tests, but in theory, such probability does exist.
If you are looking for a bulletproof formula to get a random selection with only unique values, then use RANK + COUNTIF or RANK.EQ + COUNTIF combination instead of just RANK. For the detailed explanation for the logic, please see Unique ranking in Excel.
The complete formula is a bit cumbersome, but 100% duplicate-free:
=INDEX($A$2:$A$16, RANK.EQ(B2, $B$2:$B$16) + COUNTIF($B$2:B2, B2) - 1, 1)
Notes:
- Like RANDBETWEEN, the Excel RAND function also generates new random numbers with each recalculation of your worksheet, causing the random selection to change. To keep your sample unchanged, copy it and paste somewhere else as values (Paste Special > Values).
- If the same name (number, date, or any other value) appears more than once in your original data set, a random sample might also contain several occurrences of the same value.
More ways to get a random selection with no repeats in Excel 365 - 2010 are described here: How to get random sample in Excel without duplicates.
How to select random rows in Excel
In case your worksheet contains more than one column of data, you can select a random sample in this way: assign a random number to each row, sort those numbers, and select the required number of rows. The detailed steps follow below.
- Insert a new column to the right or to the left of your table (column D in this example).
- In the first cell of the inserted column, excluding the column headers, enter the RAND formula:
=RAND()
- Double-click the fill handle to copy the formula down the column. As the result, you will have a random number assigned to each row.
- Sort the random numbers largest to smallest (sorting in ascending order would move the column headers at the bottom of the table, so be sure to sort descending). For this, head over to the Data tab > Sort & Filter group, and click the ZA button. Excel will automatically expand the selection and sort the entire rows in random order.
If you are not quite satisfied with how your table has been randomized, hit the sort button again to resort it. For the detailed instructions, please see How to randomly sort in Excel.
- Finally, select the required number of rows for your sample, copy them and paste to wherever you like.
To have a closer look at the formulas discussed in this tutorial, you are welcome to download our sample workbook to Excel Random Selection.
How to randomly select in Excel with Randomize tool
Now that you know a handful of formulas to get a random sample in Excel, let's see how you can achieve the same result in a mouse click.
With Random Generator for Excel included in our Ultimate Suite, here's what you do:
- Select any cell in your table.
- Go to the Ablebits Tools tab > Utilities group, and click Randomize > Select Randomly:
- On the add-in's pane, choose what to select: random rows, random columns or random cells.
- Specify the number or percentage for the desired sample size.
- Click the Select button. Done!
For example, this is how we can select 5 random rows from our sample data set:
And you will get a random selection in a second:
Now, you can press Ctrl + C to copy your random sample, and then press Ctrl + V to paste it to location in the same or another sheet.
If you'd like to test the Randomize tool in your worksheets, just grab a trial version of Ultimate Suite below. In case your are using Google spreadsheets, you may find our Random Generator for Google Sheets useful.
Available downloads
Selecting random sample - formula examples (.xlsx file)
Ultimate Suite - trial version (.exe file)
89 comments
"How to select a random value from a list"
I know now. Many thanks.
Hi, I have a large set of data - namely a contacts list. I'm looking to pull a random sample of customer email addresses each month. Is there a way I can do this and also pull their account manager information as well? Extra points if the data pulled doesn't repeat within 12 months.
Many Thanks in advance for any help.
Hello Beth!
You can use the recommendations from this section in the article above: How to select random rows in Excel. I recommend paying attention to the Randomize tool. See the article above for a detailed description. It is available as a part of our Ultimate Suite for Excel that you can install in a trial mode and check how it works for free.
Hi, I have large set of data, and there is one row containing same data ( suppose, if a row contains a,b,c,d in 4 different cells) the same row is repeating multiple times. I want ti pick those all specific rows and exactly two more rows below that for each specific row. How can i do this?
Hi! Add additional columns to the table. In the first column, get TRUE for the rows that contain a,b,c,d. In the second column, get TRUE for the two rows below. Then apply the Excel filter on those two columns. I can't tell you the formulas, as I don't understand what your data looks.
I have used the following formula, which gives me an error.
I am trying to pull random from another worksheet named Key.
=INDEX(Key!$B$28:$B$69,RANK($C$28:$C$69),1)
Also If I am able to make this work& I need it to pull randomly month without repeating, is there something I should add to this? Is there a way to make it start over when all selections have been randomly selected?
Thank you for your help.
Hi! Please take a look at this article: How to get random sample in Excel without duplicates. I hope it’ll be helpful.
How to select element from a list with certain frequency? If I have a list A=(45,12,6,2,1) with frequency F=(2%, 8%, 20%, 35%, 35%) respectively. I want to fill a 100 rows column with the element of the list A respecting the frequency F. How to do it? Thanks in advance
Hi!
I'm really sorry, looks like this is not possible with the standard Excel options.
how to record the output of generated random number
The fastest way is to replace formulas with calculated values. You will find step-by-step instructions in the above linked tutorial.
Hi! How are you am looking for a formular that will pick numbers rondomly in any cell in each row in each column and sum the picked number to give a given set sum. E.g.
A. B. C
2.34. 2.45. 2.56
2.56. 2.78. 2.58
2.45. 2.76. 3.89
I am looking for the formular that will randomly pick the data above which will give me this total 9.01 though this total may differ according to my needs
Hi!
Add to the INDEX formula you see in this article a random column selection.
=INDEX(A2:C15,RANDBETWEEN(1,COUNTA($A$2:$A$15)), RANDBETWEEN(1,COUNTA($A$2:$C$2)))
You can learn more about INDEX in this article: Excel INDEX function with formula examples.
I have a result of a survey, the first column is "ID of each household" and the second column is "number of person in each household". For example, if we have one household with 4 people answering the survey, we would have 4 rows, the first column is the same in all 4 cases and the second columns are 1, 2, 3 and 4. And there are many data in this way in 1 spreadsheet, but I tend to select just 1 person randomly from each household. And I want to do it for all the households.
So helpful! Thank you!
I need to pick a random selection of sports teams each week. However, the requirement is that these teams can't be playing each other on that week. Do you have a solution that meets these requirements?
For example, in any given week, if the games are as follows:
Team A vs Team B
Team C vs Team D
Team E vs Team F
Team G vs Team H
Team I vs Team J
Then a valid random selection of three teams would be:
Team C
Team F
Team H
But an invalid random selection of three teams would be:
Team A
Team B
Team J
Hello,How can I choose two or more values from a list of 10 numbers at random?
Hi,
I hope you have studied the recommendations in the tutorial above. It contains answers to your question. Pay attention to the following paragraph of the article above — How to randomly select in Excel without duplicates
If you need 2 values, use cells C2 and C3.
I hope this will help.
Hi,
i want to get a random sample from a papulation in a column, and if it could the number of this sample be calculated based on the size of the papulation.
thanks.
Hi!
Try using the recommendations from the section above: How to randomly select in Excel without duplicates. To select random values from a column, you can also use the Randomize Tool.
Hello,
I have a list of about 12,000 clients and would like to do a study on a few of them without biased selection. How do I get the random sample and determine the best sample size in Excel. if the selected random numbers would be 'highlighted'. I have tried using RAND() but not helping out as I would like. thanks so much for the help.
Hello!
You did not mention what problem you have with the RAND function.
But, we have a ready-made solution for your task.
I'd recommend you to have a look at our Ablebits Tools - Randomize.
It is available as a part of our Ultimate Suite for Excel that you can install in a trial mode and check how it works for free.
Hi, Thanks for the reply.
RAND keeps recalculating that by the time I paste values, the figures have already changed. am not able to know what percentile to take to avoid bias or have minimal error. I would a function that would help say for 500 clients you can sample out maybe 149, one with 1000 one can sample 253. like define a range for me and thereafter be able to Vlookup those particular IDs. thanks again
I want to assign a list randmoly based on the data of another cell.
on cell has 1 and 0 for yes and no while the other on is a list of