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
 

Some videos you may like

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Trebor76

Well-known Member
Joined
Jul 23, 2007
Messages
4,626
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
23,770
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.
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,792
Messages
5,513,466
Members
408,953
Latest member
Skiig

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top