![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: May 2002
Location: New Zealand
Posts: 23
|
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 |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
|
You could use the REPLACE function of Excel (Worksheetfunction.Replace) to replace "x" with the "real value". Then, use the EVALUATE method of VBA to get the correct answer.
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|