View Single Post
  #2   Report Post  
Rowan
 
Posts: n/a
Default

I am assuming you are wanting to do this in a macro as you have used Rnd and
not the worksheet function Rand. You could do it like this

Sub RandomSum()
Dim i As Long
Dim y As Double
For i = 1 To 2500000
y = y + Rnd()
Next i
MsgBox y
End Sub

but it would be a lot more efficient and probably not materially different
to do this:

Sub RandomSum()
Dim i As Integer
Dim y As Double
For i = 1 To 25
y = y + Rnd() * 100000
Next i
MsgBox y
End Sub

Hope this helps
Rowan

"RandomProblems" wrote:

I need to create the sum of 2,500,000 iterations generated by the Rnd
generator function. I cannot create y=X(1)+X(2)+......X(n) where y is the
sum and x (the first iteration, x(2) the second and so on.