Converting string into formula

jcg31

Board Regular
Joined
Aug 20, 2006
Messages
176
Is there a way in excel using VBA to convert string ( "A17*(B17+B18)/A18" ) into a executable formula?

Thanks,
Jim
 

Excel Facts

Links? Where??
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
Joined
Jul 23, 2007
Messages
4,951
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
Joined
Jan 15, 2007
Messages
24,220
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
Joined
Mar 28, 2006
Messages
200
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.
 
Master Excel Bundle

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.

Forum statistics

Threads
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.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

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

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

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
Top