Equations in excel

B

Bob

Hi all:

I was wondering if in excel macro, I can have my user input an equation in a
cell as either text or formula (for example "x^2+3*x+6"), and in my macro
read this text, and evaluate the function, and put the result in a variable,
for example y. I need this to process Newton-raphson method for any
inputted function. Thanks for your help.

Bob
 
G

Gary''s Student

The user enters the following text in A1:

x^2+3*x+6

this macro:

Sub marine()
Dim s As String
Dim v As Variant
s = Range("A1").Value
s = Replace(s, "x", ".1234")
y = Evaluate(s)
MsgBox (y)
End Sub

1. gets the expression
2. puts in some value for x
3. evalues the expression and places the result in the variable y
4. the result is also output ( you may not need this)
 
B

Bob

Thank you.

Gary''s Student said:
The user enters the following text in A1:

x^2+3*x+6

this macro:

Sub marine()
Dim s As String
Dim v As Variant
s = Range("A1").Value
s = Replace(s, "x", ".1234")
y = Evaluate(s)
MsgBox (y)
End Sub

1. gets the expression
2. puts in some value for x
3. evalues the expression and places the result in the variable y
4. the result is also output ( you may not need this)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top