Forum Discussion
Formulas and functions
If you're willing to use VBA:
Press Alt+F11 to activate the Visual Basic Editor.
Select Insert > Module.
Copy the following function into the code window:
Function Eval(s As String)
Eval = Evaluate(s)
End Function
Close the Visual Basic Editor.
Use like this in a cell formula to evaluate the expression in A2. The formula can be anywhere.
=Eval(A2)
Save the workbook as a macro-enabled workbook (.xlsm) and make sure that you allow macros when you open it.
Alternatively, you can use a defined name; this will only work in the cell to the right of the text string.
So let's say you have a text expression in A2.
Select B2.
On the Formulas tab of the ribbon, click Define Name...
Enter Eval in the Name box, and enter the formula =EVALUATE(A2) in the Refers To box, then click OK.
Enter the following formula in B2:
=Eval
Note that there is no reference to A2 in the cell formula; the reference is in the definition of Eval.
If you enter =Eval in cell D6, it will refer to C6, etc.