Apply a string value to the active cell as a real formula with cell reference

grexcelman

Board Regular
Joined
Mar 1, 2015
Messages
50
I'm halfway to solving this dilemma of mine. I have a table listing dozens of formulas some of which are custom built through a 3rd party API like Bloomberg financial(call that "FormulaTable") while others are more custom designed. A formula can be selected based on two criteria from a data table, "ApplicationTable" where I hope to apply the selected formula given a relative cell value in that table.

Because there's about a dozen different categories in the ApplicationTable, and a given formula choice is dependent on two different field options, an IF statement was not option, nor was a Vlookup. I've solved this part of the problem with an function that uses index match code in vba and named that string variable, "GetMetric" -

Specifically, what I'd like to do is have that string value(the formula chosen from the FormulaTable), get applied to my ApplicationTable as a working formula in column F and apply it with a relative cell reference to column B.

Any ideas how to express a string value as an active formula? I've seen some ideas with evaluate function but couldn't seem to get the formula to work, instead it just printed the string value in the active cell.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi,

I think you'll need to do this in VBA

this code
Code:
range("b1").formula = range("A1").Value

Would take the value in cell A1 and apply it as a formula in B1. Does this get you started?
 
Upvote 0
Hi,

I think you'll need to do this in VBA

this code
Code:
range("b1").formula = range("A1").Value

Would take the value in cell A1 and apply it as a formula in B1. Does this get you started?

Hi Dave, thanks for your reply. I suppose after I lookup my text I could print the string in an adjacent cell. then have code or a cell formula that interprets it such as the formula you wrote. How would this ultimately become an active formula where I could apply it to referenced cells? For example, if the string returned is 'Average', I'd like for the Average function to average cells 'C:F' -- if the string returned is 'STDEV', I'd like that applied on C:F instead. is this doable?
 
Upvote 0
It's achievable for sure. Can you give some examples that show

a) the text that you want to turn into a formula
b) the formula that you're expecting
 
Upvote 0
It's achievable for sure. Can you give some examples that show

a) the text that you want to turn into a formula
b) the formula that you're expecting

I'll try to send again shortly. I was timed out after I finished typing up a reply and it deleted everything including the tables I built to display as examples.
 
Upvote 0
It's achievable for sure. Can you give some examples that show

a) the text that you want to turn into a formula
b) the formula that you're expecting



I have two tables, one will house the formulas chosen by a lookup, and the other consolidates the data depending on what's in columns A and B respectively. For simplicity sake I only provided a couple of rows and just information pertaining to the first metric. I anticipate having several hundred rows of data with roughly a dozen varying metrics to be applied from the FormulaTable.

Application Table
Ticker
Sector
Metric1
Metric2
Metric3
Metric4
AAPL
TTM
=BFP("A2","Price_to_Sales",FY)
GM
PEG
P/RAW
ABBV
Biotech
=BFP("A3","Price_to_Sales",FY)
PEG
P/PIPE
EV/EBITDA

<TBODY>
</TBODY>


Formula Table
Sector
Ticker
Metric1
Metric2
Metric3
Metric4
Biotech
AMGN
'=BFP("A2","Price_to_Earnings",FY)
PEG
Profit Mgn
Gross Mgn
Biotech
ABBV
'=BFP("A2","Price_to_Sales",FY)
PEG
P/PIPE
EV/EBITDA
Finance
JPM
'=BFP("A2","Price_to_Book",FY)
P/E
EV/EBITDA
D/E
TTM
AAPL
'=BFP("A2","Price_to_Sales",FY)
GM
PEG
P/RAW

<TBODY>
</TBODY>
 
Upvote 0
Sorry for the delay in replying.

So you have a formula in each table (Metric1) that's present as text(?) that you need to be converted to an active formula?
 
Upvote 0
No worries. That's correct. My code will pick through a table of formulas listed as text and after retrieved based on a vlookup/index-match I want my code to insert the text as a formula that can reference a cell in the retrieval table(ApplicationTable).
 
Upvote 0
So you code either use the code above, or create a UDF utilising the evaluate function..

Code:
Function ConvertTextToFormula(rInput As Range) As Variant
fOutput = Evaluate(rInput.Value)
ConvertTextToFormula = fOutput
End Function

Is that any use at all or am I missing the point?
 
Upvote 0
You might consider using R1C1 notation in your Metric1 column, so you don't have to adjust for formulae being put into different cells.
 
Upvote 0

Forum statistics

Threads
1,215,784
Messages
6,126,878
Members
449,347
Latest member
Macro_learner

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