Hi thanks for the feedback - I get what you mean, that is helpful and I appreciate that but it does not fix the problem.

When the function runs with input value of "404.0404"
for 100 iterations, it returns the incorrect value of 1
where as the sheet column formula returns the correct
value of "72.18545607"

The UDF VBA function is not retaining any values past the decimal position
nor is it properly calculating the end result.

I suspect this is related to data type and how excel is handling the calcs in
VBA, but I cant figure out how to fix this as I have tried all known relevant data types.

Its easy to see what I mean by simply entering any value for input thats
a rational number and for any loops higher than 10, the spreadsheet using basic repeat and copy columnwise statements of what I mentioned above ;

"The first formula placed at (E2) looks like ; =MOD(((B2^2)),$B$4)
In (E3) this statement is placed ; =MOD(((E2^2)),$B$4)"

Then comparing the 100th cell to the 100th iteration of the function demonstrates the discrepancy, I just want the function to return the same value and accuracy that the far more cumbersome sheet / column based
approach produces



Quote Originally Posted by OptionBase1 View Post
You mention an error, but I'm assuming you mean unexpected results rather than an error message.

Based on your textual description of the intended order of events, and your example formulas that you report are working properly, the error appears to be an order of operations error in your vba code. In your code, "SQRD Mod 400" takes place before "/ decx".

So, this should do things in the order you describe.

Code:
For Count = 1 To looptime
    SQRD = CDec(SQRD ^ 2)  '+ looptime
    SQRD = CDec(SQRD / decx)  Mod 400
Next Count