Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Selecting Random Names.

# Selecting Random Names

by Allen Wyatt
(last updated November 22, 2019)

A common task for many people is to pick a number of random names from a large list. For instance, you may be running a contest for your community, and you have 1,000 people that have entered. With their names in each row of a table, you may be wondering how to select a certain number of the names randomly.

As is often the case with Excel, there are a number of different approaches you can take. Each approach examined in this tip assumes that the names you need to select from are listed in cells A1 through A1000. Of course, your range of names could be shorter or longer, but the point is that they are in contiguous cells in column A. The examples also assume that you need to select 15 names at random from the list.

The first approach is to use the INDEX function. Enter the following formula in cells B1:B15:

```=INDEX(A:A,INT((RAND()*1000)+1),1)
```

A similar formula uses the OFFSET function:

```=OFFSET(\$A\$1,ROUNDUP(RAND()*1000,0),0,1,1)
```

It is possible, but not probable, that you will get the same name twice in the resulting list. (The improbability comes because of the size of the original list. The larger the list, the less probable there will be duplicates in the extracted list.) If you do get a duplicate name, then simply force a recalculation of your worksheet by pressing F9. Each time your recalculate, the list of extracted names is regenerated.

Another potential approach requires the use of multiple columns. Simply follow these steps:

1. Enter =RAND() in cell B1.
2. Enter the following formula in cell C1:
3. ```     =RANK(B1,\$B\$1:\$B\$1000)
```
4. Select the range B1:C1, and fill down to row 1000.
5. Select the range B1:C1000.
6. Press Ctrl+C to copy the range to the Clipboard.
7. Choose Paste Special from the Edit menu. Excel displays the Paste Special dialog box. (See Figure 1.)
8. Figure 1. The Paste Special dialog box.

9. Make sure the Values radio button is selected.
10. Click on OK. You now have static values in B1:C1000, which means they won't change every time the worksheet is recalculated.
11. Select a cell in column C.
12. Choose Sort from the Data menu. Excel displays the Sort dialog box. (See Figure 2.)
13. Figure 2. The Sort dialog box.

14. Click on OK. The table (range A1:C1000) is sorted according to the values in column C.

The result is that column C now contains a ranking of all the random numbers in column B. The first 15 rows contain your random names.

In this approach you could also have left out column C completely and simply sorted your list based on the static random values in column B. Again, the top 15 would be your random names.

Of course, there are any number of macro solutions you could use for this problem. The coding of any macro will be similar, relying on VBA's RND function to generate random numbers. Of all the possible macro solutions, perhaps the following is the most unique and offers some advantages not available with the workbook solutions discussed so far:

```Sub GetRandom()
Dim iRows As Integer
Dim iCols As Integer
Dim iBegRow As Integer
Dim iBegCol As Integer
Dim J As Integer
Dim sCells As String

Set TempDO = New DataObject

iRows = Selection.Rows.Count
iCols = Selection.Columns.Count
iBegRow = Selection.Row
iBegCol = Selection.Column

If iRows < 16 Or iCols > 1 Then
MsgBox "Too few rows or too many columns"
Else
Randomize Timer
sCells = ""
For J = 1 To 15
iWantRow = Int(Rnd() * iRows) + iBegRow
sCells = sCells & Cells(iWantRow, iBegCol) & vbCrLf
Next J
TempDO.SetText sCells
TempDO.PutInClipboard
End If
End Sub
```

To use this macro, just select the names from which you want to select the 15 random names. In the examples thus far, you would select the range A1:A1000. The macro then pulls 15 names at random from the cells, and puts them in the Clipboard. When you run the macro, you can then paste the contents of the Clipboard where ever you want. Every time the macro is run, a different group of 15 is selected.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2811) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Selecting Random Names.

##### Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

##### MORE FROM ALLEN

Understanding and Creating Lists

There are two types of common lists you can use in a document: bulleted lists and numbered lists. This tip explains the ...

Discover More

Unwanted Vertical Lines in a Table

When you print a table that includes borders, those borders should be crisp and clear on the printout. If you get some ...

Discover More

Printing a Chart Across Multiple Pages

Wouldn't it be great to have your huge charts print out on multiple pieces of paper that you could then piece together? ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

Returning a Blank Value

Is it possible for a formula to return a blank value? It depends on how you define your terms. This tip examines all the ...

Discover More

Converting to Octal

If you need to do some work in the base-8 numbering system (octal), you'll love two worksheet functions provided by Excel ...

Discover More

Numbers in Base 12

Different professions use numbers in entirely unique ways. You may need to come up with a number that represents the ...

Discover More
##### Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. Youâ€™ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 5 - 2?

2016-05-11 13:53:59

Devanand

I need an excel formula or vba code to select 5 random vales from one sheet to another.

Thank You,

2015-04-27 20:54:00

reytoch

Good article

What I have seen so far look so nice. If I would like to assign specific person or name in among 15 random name. How could I do?

2013-06-24 09:26:55

Ken

Another option is to number each of your 'contestants', then use =VLOOKUP(RANDBETWEEN(1,1000),A1:B1000,2,0).

##### This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.