Why doesnt this function work what it calls onitself? Excel VBA

42 Views Asked by At

I am trying to make a UDF that does integration on function specified in some cell.

for that i have made this beautiful function that almost works:

Function EvaluateFormula(ByVal Variable As Double, ByVal FormulaCell As Range) As Double
    Dim Formula As String
    Dim result As Double
    
    ' Get the formula from the cell
    Formula = UCase(FormulaCell.Formula)
    Formula = Replace(Formula, "VARIABLEX", Variable)
    
    ' Evaluate the modified formula and return the result
    result = Application.Evaluate(Formula)

    EvaluateFormula = result
End Function

Function works fine with all kinds of UDF that i can pass thru the formulacell but if i try to pass function where Evaluateformula() is used or any another function that result contains Application.Evaluate it fails to get result? i guess its impossible to run application.evaluate within application evaluate? What could I do?

0

There are 0 best solutions below