2.4 C
London
Friday, December 20, 2024
HomeSoftware TutorialsExcelExcel: How to Randomly Select Cells Based on Criteria

Excel: How to Randomly Select Cells Based on Criteria

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

Often you may want to randomly select a cell based on specific criteria in Excel.

This tutorial provides two examples of how to do so using the following dataset in Excel:

Example 1: Randomly Select Cell Based on One Criteria

We can use the following formula to randomly select one player who is on the Mavs team:

=INDEX(A2:A14,LARGE(IF(B2:B14=A17,ROW(B2:B14)-ROW(B2)+1),INT(RAND()*COUNTIF(B2:B14,A17)+1)))

This particular formula will randomly select one cell from the range A2:A14 where the corresponding cell in the range B2:B14 is equal to the value in cell A17.

We can type this formula into cell A20 and then press Ctrl + Shift + Enter:

Excel random selection with criteria

We can see that the formula randomly selected Luka, who is a player on the Mavs team.

Feel free to double click cell A20 and press Enter to run the formula again.

Each time we run the formula, it’s possible that we will get a different player on the Mavs team.

Example 2: Randomly Select Cell Based on Multiple Criteria

We can use the following formula to randomly select one player who is on the Mavs team and is a Guard:

=INDIRECT("A"&LARGE(IF($B$2:$B$14=$A$17,IF($C$2:$C$14=$B$17,ROW($A$2:$A$14),0),0), RANDBETWEEN(1,COUNTIFS(B2:B14,A17,C2:C14,B17))))

This particular formula will randomly select one cell from the range A2:A14 where the cell in range B2:B14 is equal to the value in cell A17 and the cell in range C2:C14 is equal to the value in cell B17.

We can type this formula into cell A20 and then press Ctrl + Shift + Enter:

We can see that the formula randomly selected Reggie, who is a guard on the Mavs team.

Feel free to double click cell A20 and press Enter to run the formula again.

Each time we run the formula, it’s possible that we will get a different guard on the Mavs team.

Additional Resources

The following tutorials explain how to perform other common tasks in Excel:

How to Select a Random Sample in Excel
How to Remove Duplicate Rows Based on Two Columns in Excel

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories