Random value from list or table

Excel formula: Random value from list or table

To get a random value from a table or list in Excel, you can use the INDEX function with help from the RANDBETWEEN and ROWS functions.

In the example shown, the formula in G7 is:

=INDEX(data,RANDBETWEEN(1,ROWS(data)),1) 

Generic formula

=INDEX(data,RANDBETWEEN(1,ROWS(data)),1)

Explanation

Note: this formula uses the named range "data" (B5:E104) for readability and convenience. If you don't want to use a named range, substitute $B$5:$E$104 instead.

To pull a random value out of a list or table, we'll need a random row number. For that, we'll use the RANDBETWEEN function, which generates a random integer between two given values - an upper value and lower value.

For the lower value, we use the number 1, and for the upper value we use the ROWS function to get count the total rows in the table or list:

=RANDBETWEEN(1,ROWS(data)) 

RANDBETWEEN will return a random number between 1 and the count of rows in the data, and this result is fed into the INDEX function for the rows argument. For the columns argument, we simply use 1, since we want a name from the first column.

So, assuming that RANDBETWEEN returns 7 (as in the example) the formula reduces to:

=INDEX(data,7,1) 

Which returns the name "Tim Moore", in row 7 of the table.

Note that RANDBETWEEN will recalculate whenever a worksheet is changed or opened.

Related formulas

Excel formula: Random number between two numbers

Random number between two numbers

The Excel RANDBETWEEN function returns a random integer between given numbers. In the example shown, the formula in B5 is: =RANDBETWEEN(1,100) This formula is then copied down from B5 to B11. The result is random numbers between 1-100. RANDBETWEEN is a volatile function that recalculates when a.

Excel formula: Random date between two dates

Random date between two dates

The RANDBETWEEN function takes two numbers, a bottom and top number, and generates a random integer in between. Dates in Excel are serial numbers, so you can use the DATE function to create the lower number and the upper number. RANDBETWEEN then generates a number that falls between these two date.

Excel formula: <a href=Randomly assign data to groups" width="292" height="191" />

Randomly assign data to groups

In this example, the goal is to return a random group ("A", "B", or "C") at each new row. The simplest way to do this is to use the RANDBETWEEN function with the CHOOSE function. In the current version of Excel, it is also possible to generate all random groups in one step with the RANDARRAY.

Excel formula: Random text values

Random text values

The CHOOSE function provides the framework for this formula. Choose takes a single numeric value as its first argument (index_number), and uses this number to select and return one of the values provides as subsequent arguments, based on their numeric index. In this case, we are using four values.

Excel formula: Random number from fixed set of options

Random number from fixed set of options

The CHOOSE function does most of the work in this formula. Choose takes a single numeric value as its first argument (index_number), and uses this number to select and return one of the values provides as subsequent arguments, based on their numeric index. In this case, we are providing four.