Select a random name with a changing array

MacAlexandreL

New Member
Joined
May 15, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have to do 150 random draws to choose between 4 names, let's say A B C and D. But depending on the draw, sometimes there is only A and D participating, or A, C and D, etc. So the array is changing.

I know this formula could do it if the array was always the same: =INDEX(I8:L8,RANDBETWEEN(1,COUNTA(I8:L8)))
But I would like to use the formula on several rows, and sometimes in the array (I8:L8) there are some blank cells (if everyone is not participating. Indeed, there is a maximum of 4 people and a minimum of 1, depending on each row.

But when there isn't 4 names, the formula can retrieve a blank cell instead of a name. So I would like to know if I can add a criteria to the array (something to ignore when there is a blank cell).
As there are over 150 rows, I would like to know if there is a way to solve this problem or if I will have to adapt the array manually for each row...

Thank you for your precious help !

Alexandre
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi & welcome to MrExcel.
How about
Excel Formula:
=INDEX(FILTER(I8:L8,I8:L8<>""),RANDBETWEEN(1,COUNTA(I8:L8)))
 
Upvote 0
Hi,
Thank you for your answer, I think I am going to love this forum!
I haven't tried with filter before. With your formula, I either get a name or #REF! (before I had just a blank cell and now I have REF!).

Do you have an idea why?
 
Upvote 0
Sounds like you might have some null strings in there. Try
Excel Formula:
=LET(Fltr,FILTER(I8:L8,I8:L8<>""),INDEX(Fltr,RANDBETWEEN(1,COUNTA(Fltr))))
 
Upvote 0
Maybe...

Pasta1
IJKLM
7NAMENAMENAMENAMERandom
8JohnMikeMaryPeterMike
9PeterRobertAnthonyPeter
10JoanaMichaelMichael
11BarbraLisaJohnJohn
12JoeRitaJoe
13FrankTomBobBob
14CharlesWilliamCharles
15PaulPaul
Plan1
Cell Formulas
RangeFormula
M8:M15M8=INDEX(I8:L8,MATCH(RANDBETWEEN(1,COUNTA(I8:L8)),INDEX(SUBTOTAL(3,OFFSET(I8,,,1,COLUMN(I8:L8)-COLUMN(I8)+1)),0),0))


M.
 
Upvote 0
Sounds like you might have some null strings in there. Try
Excel Formula:
=LET(Fltr,FILTER(I8:L8,I8:L8<>""),INDEX(Fltr,RANDBETWEEN(1,COUNTA(Fltr))))
IT IS WORKING ! Thank you very much ! You lost me there, I have no idea what you did with let and Fltr but it is working ! you saved me a lot of time, thanks ! see
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
Maybe...

Pasta1
IJKLM
7NAMENAMENAMENAMERandom
8JohnMikeMaryPeterMike
9PeterRobertAnthonyPeter
10JoanaMichaelMichael
11BarbraLisaJohnJohn
12JoeRitaJoe
13FrankTomBobBob
14CharlesWilliamCharles
15PaulPaul
Plan1
Cell Formulas
RangeFormula
M8:M15M8=INDEX(I8:L8,MATCH(RANDBETWEEN(1,COUNTA(I8:L8)),INDEX(SUBTOTAL(3,OFFSET(I8,,,1,COLUMN(I8:L8)-COLUMN(I8)+1)),0),0))


M.
Hi ! Thank you for your answer ! It is also working ! Thank you very much ! I don't know why and how, but that's great ! Have a good day
 
Upvote 0
You could have also done it with this small change to Fluff's original formula

=INDEX(FILTER(I8:L8,I8:L8<>""),RANDBETWEEN(1,COUNTA(I8:L8)))
=INDEX(FILTER(I8:L8,I8:L8<>""),RANDBETWEEN(1,COUNTIF(I8:L8,"?*")))

.. or another way
=INDEX(SORT(I8:L8,,-1,1),RANDBETWEEN(1,COUNTIF(I8:L8,"?*")))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,026
Messages
6,122,738
Members
449,094
Latest member
dsharae57

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top