Re: recalculating RAND() inside a VBA loop
- From: Dave Peterson <petersod@xxxxxxxxxxxxxxxx>
- Date: Wed, 24 Sep 2008 20:59:02 -0500
Calling the function from another function or sub wouldn't be a problem.
It'll be a problem when the function originates in a cell on a work***.
We'll see (maybe) who guessed right <vbg>.
Jim Cone wrote:
Hi Dave,
I called the function from a sub.
The ActiveCell had "=RAND()" in it...
'---
Sub huh()
MsgBox expval(ActiveCell, 5)
End Sub
'---
Jim Cone
Portland, Oregon USA
"Dave Peterson"
wrote in message
About the only thing that a function called from a work*** cell can do is
return a value to the cell with the function.
Application.calculate fails for me (xl2003).
Maybe you could use VBA's Rnd function instead of looking back at the
work***???
Option Explicit
Function expval(Optional iter As Long) As Double
Dim arr() As Double
Dim loops As Integer
Dim X As Long
Randomize
'set itterations
loops = Application.WorksheetFunction.Max(iter, 20)
'set array
ReDim arr(1 To loops)
'loop through value measurements
For X = 1 To loops
arr(X) = Rnd
Next X
'compute average value
expval = Application.WorksheetFunction.Average(arr)
End Function
Dave Peterson
--
Dave Peterson
.
- References:
- recalculating RAND() inside a VBA loop
- From: vbaRay
- Re: recalculating RAND() inside a VBA loop
- From: Dave Peterson
- Re: recalculating RAND() inside a VBA loop
- From: Jim Cone
- recalculating RAND() inside a VBA loop
- Prev by Date: Re: recalculating RAND() inside a VBA loop
- Next by Date: RE: Bolding a Cell under certain conditions
- Previous by thread: Re: recalculating RAND() inside a VBA loop
- Next by thread: MACRO - INSERT ROW
- Index(es):