Pick a Random Name from a Long List in Google Sheets

Published on

It’s easy to pick a random name from a lengthy list in Google Sheets. How do we keep it static, avoiding refresh with sheet changes?

Is it possible to prevent the randomly selected name from updating each time we input any value into a cell in Google Sheets?

Absolutely! This can be accomplished by leveraging LAMBDA, one of the revolutionary enhancements introduced in Google Sheets recently.

Moreover, my formula offers an additional feature.

Some users have expressed interest in avoiding repeated random names when dragging the formula downward. I have also incorporated that functionality.

Random Name Selection from Sheets List

Step-by-Step Instructions

Let’s assume you have a lengthy list of student names in cells A2:A in Google Sheets. Your goal is to select a random name.

You can achieve this by using a simple formula. The formula will randomly select a name from the list in the formula cell. However, it will refresh whenever changes are made in the sheet, fetching a new name each time.

Now, let’s begin with that formula and modify it so it doesn’t refresh when changes are made to the sheet.

Basic Formula for Selecting a Random Name from a Long List

You can utilize the following formula in any cell outside the range A2:A to obtain a random name from the specified range (long list).

=INDEX(A2:A, RANDBETWEEN(1, COUNTA(A2:A)))

The COUNTA function calculates the number of names in the range, while RANDBETWEEN generates a random number between 1 and the total count of names.

The INDEX function then retrieves a value by offsetting that many rows within the range.

This is the simplest method for selecting a random value from a long list in Google Sheets.

How Can I Keep the Selected Random Name Static?

I’ve highlighted the issue with the previous formula: whenever changes are made in the sheet, RANDBETWEEN refreshes, generating a new random number. Consequently, INDEX offsets by that many rows, yielding a new name.

Here are the step-by-step instructions to address this issue.

Step 1: Creating the Drop-Down:

To address this, we can introduce a drop-down box with options Yes/No to control refreshing.

  1. Navigate to cell B3.
  2. Go to the Insert menu and click Drop-down.
  3. Replace “Option 1” with “Yes” and “Option 2” with “No.”
  4. Select “Done.”
Yes/No Dropdown for Name Picker

Alternatively, you can insert a Yes/No drop-down by navigating to the desired cell, typing “@”, and selecting Drop-downs > Yes/No from the context menu.

Step 2: Converting the Formula to an Unnamed Lambda Function:

Generic Formula:

=LAMBDA(x, IF($B$3="Yes", x, ""))(basic_formula)

This unnamed LAMBDA function operates as follows:

If B3 equals “Yes”, return ‘x’, otherwise return blank. Here, ‘x’ represents the basic formula.

Here’s the formula to pick a random name from a list in column A and remain unchanged until you select ‘No’ in the drop-down:

=LAMBDA(x, IF($B$3="Yes", x, ""))(INDEX(A2:A, RANDBETWEEN(1, COUNTA(A2:A))))

You can enhance this formula by incorporating the LET function as follows:

=LET(range, A2:A, LAMBDA(x, IF($B$3="Yes", x, ""))(INDEX(range, RANDBETWEEN(1, COUNTA(range))))

In this version, we’ve assigned the name ‘range’ to A2:A.

How to Choose Multiple Unique Random Names from a Long List

The above formula is designed for selecting one random name from the list.

To pick multiple unique random names from the list, you’ll need to modify the formula as follows:

Replace A2:A with the following FILTER formula: FILTER($A$2:$A, NOT(IFERROR(XMATCH($A$2:$A, $C$1:C1))))

So the formula will be:

=LET(range, FILTER($A$2:$A, NOT(IFERROR(XMATCH($A$2:$A, $C$1:C1)))), LAMBDA(x, IF($B$3="Yes", x, ""))(INDEX(range, RANDBETWEEN(1, COUNTA(range)))))

Once you’ve applied this formula to cell C2, click and drag the bottom right fill handle of cell C2 downwards to obtain more unique random names.

Sample Sheet

Important: If you encounter any issues with the formula, navigate to cell C2, copy it, delete the existing content by pressing the delete button, and then paste the copied formula.

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Expert Prashanth KV is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. With years of experience working with Google Sheets and Excel for multinational firms in Mumbai and Dubai, he has been blogging since 2012, offering practical, real-world spreadsheet solutions that professionals rely on. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Mode of Comma-Separated Numbers in Excel (Dynamic Array)

There is no dedicated function in Excel to directly find the mode of comma-separated...

How to Find Mode of Comma-Separated Numbers in Google Sheets

Working with comma-separated numbers inside a single cell is a common scenario in Google...

How to Count Merged Cells in Google Sheets (and Get Their Size)

Sometimes, you may have blocks of merged cells in a column or row. But...

Count Consecutive Workday Absences in Google Sheets

This tutorial offers a powerful formula-based solution to count consecutive workday absences in Google...

More like this

How to Find Mode of Comma-Separated Numbers in Google Sheets

Working with comma-separated numbers inside a single cell is a common scenario in Google...

How to Count Merged Cells in Google Sheets (and Get Their Size)

Sometimes, you may have blocks of merged cells in a column or row. But...

Count Consecutive Workday Absences in Google Sheets

This tutorial offers a powerful formula-based solution to count consecutive workday absences in Google...

14 COMMENTS

  1. Thanks a lot! Your formula was very simpler compared to the one I found from another site. However, on that site, I learned I can simply press Ctrl+R to generate another name.

  2. Hi there,

    This is a great article! I’m having an issue where I have more than one of these in the same sheet and when I change one, the other formula resets. How do I make sure that changing one Yes to No doesn’t affect the other formula?

    Thanks!

    • Hi, Casey,

      Seems you want to pick multiple random names. So instead of keeping two lists and two formulas in the same sheet, make it as one list and use another formula.

      I have another tutorial. See the second link under the related post above.

      Best,

  3. Hi,

    Good day!

    I tried using the formula and I am sure that I have placed them in the right cells and columns. However, the picker seems to do not stop shuffling names. It runs like a loop.

  4. How can I control the trigger? I noticed the random value changes everytime I make any change in any other cell.
    How can I use the trigger only once so that the random value does not change on any other change?

    • Hi, Damon,

      I think you want to deliberately exclude one name appearing in the random list. In the formula replace the range A2: A (both in Index and Counta) with the filter formula as below.

      filter(A2:A,A2:A<>"the name to exclude")

      See if this works.

  5. Thank you for writing such an useful article. I am getting parse error whenever I try use function below in my google spreadsheet.

    =if(B3=”Yes”,iferror(index(A2:A,randbetween(1,counta(A2:A))),”No Name!”),””)

    It would be very helpful if you can help me in solving this problem.

    Thank you in advance.

    • Hi Ashish,

      If you copy my formula, you should retype all the double quotes in the formula. Because I’ve pasted the formulas in my post as blockquotes.

      Now I’ve modified it as a code. Either retype the double quotes or copy the formula again from my page.

      Hope this may solve the problem.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.