I am trying to create a used defined function that will calculate a Triangular distribution. I actually thought I had it working but the best I can do is return the formula to the cell the function is called from. That is entered as text.
this is the function as written.
Public Function Triang4(mn, md, mx)
rr = “=rand()”
Triang4.Value = “= IF(rr=((md-mn)/(mx-mn)),md,IF(rr<((md-mn)/(mx-mn)),mn+SQRT(rr*(mx-mn)*(md-mn)),mx-SQRT((1-rr)*(mx-mn)*(mx-md))))"
'ActiveCell.Value = x
'Calculate
End Function
I have tried using active cell as the result cell. I have dropped "value" off the result so Triang4. The formula does work if entered in a cell and I have named the cells wi the mn,md,mx and rr values. I cannot call the rand function from within the formula as the number will change each time it is called. The error returned is value if I just use the name of the function, using value active cell etc.
Thanks for any suggestions
Peter