Converting text to formulas

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to streamline a mathematical optimization program that I wrote in
Excel with a macro. Say that I have typed a formula into cell A1 as a text
string, such as "x^2+10*x^4". Next I have renamed cell B5 as "x". I want
the cell C5 to convert the formula written as a text in A1 to the formula
"=x^2 +10*x^4" which will reference cell B5 and calculate it without having
to manually copy in the equation from A1.

I tried the Visual Basic Range.Formula= function but this only returns a
text. Substitute() and Text() do not seem to work either. Does anyone know
how to do this?
 
I tried using that, but it still only returns a text string, at least with
the way that I am using it.
 
you're correct. INDIRECT only resolves a cell/range reference, not an entire
formula.

Ok, via VBA then. Try this macro:

Sub CalcFormula()
Dim myFormula As String
myFormula = Range("A4").Value
Range("C4").Formula = "=" & myFormula
End Sub

Create a button and hook it up to the macro. A4 contains your formula in
"plain text", C4 will have the calculated result.

Tieske
 
See Evaluate Method in Excel Help!

Regards,
Stefi


„Eutrapelia†ezt írta:
 
Thanks,

I was able to get it to work. It was a bit cumbersome, since I had to use
the Evaluate the function every time that the values changed, but it worked
well.

Jeremy
 
Can you use a UDF?

Function EvalCell(RefCell As String)
EvalCell = Evaluate(RefCell)
End Function

=EvalCell(A1) returns 2576


Gord Dibben MS Excel MVP
 

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

Back
Top