View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
mslabbe mslabbe is offline
external usenet poster
 
Posts: 24
Default Randomly selecting a cell weighted on percentage

Thanks Jim, but it looks like I will be stuck with the percentages, right?
Or I have to change the array in the formula you have made...would you have a
way that when the percentages change, that the formula change? And if I
added another fruit?

Thanks again

"Jim Cone" wrote:

Sub WeighTheChoices()
Dim varArr As Variant
Dim N As Long
'Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Randomize
N = Int(10 * Rnd)
varArr = Array(10, 20, 20, 30, 30, 30, 40, 40, 40, 40)
MsgBox "The winner is the one with a " & varArr(N) & "% chance. "
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"mslabbe"
wrote in message
I'm trying to figure out away that I can randomly pick an item from a range
and have the random function be weighted. So lets say in cell A1 = apples,
B1 = bananas, C1 = pears and D1 = oranges. In the cells below them are there
chances, the higher the %, the better the chance it will be selected. So for
instance, A2 = 30%, B2 = 20%, C2 = 40% and D2 = 10%. So, C2 has the best
chance at being randomly selected.

Anyone have any ideas on how to accomplish this? I really do not know where
to even begin. So, any help or ideas would be greatly appreciated.