# Converting string into formula

#### jcg31

##### Board Regular
Is there a way in excel using VBA to convert string ( "A17*(B17+B18)/A18" ) into a executable formula?

Thanks,
Jim

### Excel Facts

If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

#### Trebor76

##### Well-known Member
Hi Jim,

The following will calculate and return the result of a string to a message box:

Code:
``````Sub Macro1()

Dim strMyFormula As String

strMyFormula = "A17*(B17+B18)/A18"

MsgBox Evaluate(strMyFormula)

End Sub``````

Does that help?

#### mikerickson

##### MrExcel MVP
If you have the string "A17*(B17+B18)/A18" in A1

and define a name Name: CalculatedValue RefersTo: Evaluate(Sheet1!\$A\$1)

putting =CalculatedValue in a cell will have the same effect as putting =A17*(B17+B18)/A18 in that cell.

#### Mr_Roscoe

##### Board Regular
Jim - should be able to try these:

Range("C18").Formula = "=A17*(B17+B18)/A18"

or

Range("C18").FormulaR1C1 = "=R[-1]C[-2]*(R[-1]C[-1]+RC[-1])/RC[-2]"

CHEERS, Ian R.

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

1,168,109
Messages
5,857,438
Members
431,879
Latest member
KiwDaWabbit

### We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

### Which adblocker are you using?

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

### Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

### Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back