- Computers & Software»
- Computer Software
Select a Name at Random from a List
A useful Excel skill is to be able to select a name at random from a list. This is useful when performing a draw for a sports competition or trying to fairly pick a competition winner.This can then be expanded upon to randomly select any value from a list.
Set Up the Sheet
The image below show a basic set up of the sheet for selecting a name at random from the list.
The Rand column will be used to randomly pick a number from 0 to 1. The rank column will then be used to uniquely rank the number. This rank will then be used to produce a name from C4:C11 and display it in E4.
Use the RAND Function
The RAND function will be used to randomly produce a number between 0 and 1. The function should be entered as =RAND() in cells A4:A11.
The RAND function will recalculate every time you perform an action in Excel. This is not what we want. To gain control over when formulas are performed in Excel, you need to switch the formulas from automatic to manual.
1. Click the Formulas tab on the Ribbon
2. Click the Calculation Options button in the Calculation group
3. Select Manual from the listNo formulas in the workbook will work now until we tell them to. We will create a button to run the formulas later in this article.
Uniquely Rank each Name
The next step is to assign a unique number to each name in the list. The formula below should be entered in cell B4 and copied down to cell B11.
This RANK function is used to rank the number in cell A4 within the range of A4:A11. The second part of the formula is used to make the number unique if there is a conflict.
Select the Name from the List
In cell E4 a VLOOKUP function will be used to return the name that is assigned the number 1. The VLOOKUP function will look like below.
Create a Button to Run the Formulas
We will create a button to run the formulas in the worksheet by using a macro. First of all, let’s create the button.
1. Click the Developer tab on the ribbon
2. Click the Insert button in the Controls Group
3. Select the Button (Form Control) from the list
4. Draw the button onto the worksheet
5. The Assign Macro dialogue box. Click the New button
6. The Visual Basic Editor appears and a module is inserted ready for you to enter some VBA code for your button. Enter the code below to calculate the formulas on the worksheet
7. Close the Visual Basic Editor
8. Type a name for your button
The worksheet is completed. Click the button to select a name at random from the list. The formulas will only run when you click the button.