Actually I think the problem was in the looping construct. It seems to be coming up with an error at the same test. I'm not sure whether or not it is the random number combination or the loop itself. (Does the seed reset itself, that may be why?)

Code:

Sub TestPoissonInv() Dim topMean, topLambda As Integer, x, lambda As Double, i, j, k As Long, ws As Worksheet
'topMean is the the highest value that the mean can be
j = 2
Set ws = ActiveSheet
ws.Cells(1, 1) = "X"
ws.Cells(1, 2) = "lambda"
ws.Cells(1, 3) = "Poisson.Dist"
ws.Cells(1, 4) = "PoissonInv"
ws.Cells(1, 5) = "Check"
For topLambda = 1 To 50
For topMean = 1 To 100
For i = 2 To 10 ^ 3
x = Application.WorksheetFunction.RoundDown(Rnd() * topMean, 0)
lambda = Rnd() * topLambda
ws.Cells(j, 1) = x
ws.Cells(j, 2) = lambda
ws.Cells(j, 3) = "=POISSON.DIST(" & x & "," & lambda & ", TRUE)"
ws.Cells(j, 4) = IIf(ws.Cells(j, 3) = 1, "N/A", "=POISSONINV(" & ws.Cells(j, 3) & "," & lambda & ")")
ws.Cells(j, 5) = (ws.Cells(j, 1) = ws.Cells(j, 4))
j = j + 1
Next i
Next topMean
Next topLambda
End Sub

## Like this thread? Share it with others