On 2002-05-09 18:16, andrew.ward wrote:

Hi all,

I have formula as a text string. Is there a method of evaluating this equation directly in VBA rather than using string manipulation functions to extract the numerical values in order to create a new function?

That is, I have can obtain the equation of a trendline as a string. Can I evaluate this directly using some type of string evaluation function, and if so how? Or do I have to use the laborious string functions to extract the coefficients and recreate the function using variables?

E.G.

Dim x as double

Dim y as double

Dim TrendlineEquation as string

TrendlineEquation = 2.6667*x + 11.44

x=2

y= SomeTypeOfEvaluationFunction (TrendlineEquation)

Or to put it another way:

y= SomeTypeOfEvaluationFunction (2.6667*x + 11.44)

Nb the value of y should be 16.77

Thanks so much,

Andrew

[ This Message was edited by: andrew.ward on 2002-05-09 21:10 ]
Hi Andrew...if I read you post correctly it

looks like your trying to evaluate the

Trend line eqaution from a chart Trend.

If so then try this;

Sub test()

Dim x As Double

Dim y As Double

Dim TrendlineEquation As String

Dim Rp As Double

Rp = 2

TrendlineEquation = "2.6667 * x + 11.44"

TrendlineEquation = Replace(TrendlineEquation, "x", Rp)

y = ExecuteExcel4Macro("Evaluate(" & TrendlineEquation & ")")

MsgBox y

End Sub

## Like this thread? Share it with others