If Equation is passed as a string, it must be entered as such - with QUOTES. In a cell: =SIGMA(5,1,"4*i+6")
And here's the UDF (which assumes you actually wanted to use the incremented "a" value, not the static "i" value):
Function SIGMA(ByVal n As Long, ByVal i As Long, ByVal Equation As String) As Double
Dim EQ As String, Accum As Double, a As Double
For a = i To n
EQ = Replace(Equation, "i", CStr(a))
Accum = Accum + Evaluate(EQ)
Next a
SIGMA = Accum
End Function
BTW, your original code was needlessly recursive. Just accumulate the value in the loop and assign it to SIGMA after.
Bookmarks