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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
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?
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,267
Members
449,075
Latest member
staticfluids

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
Back
Top