View Single Post
  #5   Report Post  
JE McGimpsey
 
Posts: n/a
Default

Richard forgot to make this the last line in his function (before "End
Function"):

CoinFlip = No_Heads

Note that this will calculate once only (unless you do a full recalc on
the worksheet). If you want it to recalculate every time a formula on
the sheet is calculated, add Application.Volatile at the beginning of
the function. This is functionally equivalent:

Public Function CoinFlip(NumFlips As Long, pHeads As Double) As Long
Dim i As Long
Dim nHeads As Long
Application.Volatile
For i = 1 To NumFlips
nHeads = nHeads - (Rnd < pHeads)
Next i
CoinFlip = nHeads
End Function


In article ,
igor eduardo k?pfer wrote:

Richard, thanks for the response. I tried function you've given me, but it
returns only zeros. Did I do something wrong?