What is the simplest formula I can use to randomly choose a value in column A that is associated with a given B value. So in the table below, I’m looking to randomly choose an A where B = 3. So I’m randomly choosing between row 1 (5.4) and row 3 (4.2). Note that this table can be arbitrarily large.
A B
1 5.4 3
2 2.3 1
3 4.2 3
4 9.2 2
... ...
Conceptually you could do it a number of ways, but here’s one (VBA) where you’d use an array of possible choices then get a random element from that list:
UPDATE:
Here is a code example that loops through the range for the number you specify, and if it find it, it adds the A column value to an array of possible results. Then a random number is generated and used to return a random value from that list.
Optimization:
Here is a more flexible version of the same function. It takes 3 paramteres – the range you want to look in, what you want to find, and the offset value of the cell you want a random result from. It also uses Variants, so you can search for text or numbers. So in your case, you’d write:
Here is the code: