1
votes

I have a table in an excel 2010 workbook (result_master.xls). Column A has Name, Column B has a Formula see example below

enter image description here

In another workbook(user_result_sheet.xls) I have a table where I want to use a VLOOKUP to return the appropriate formula in cell $B$2 from the table array in the other workbook based on lookup value from cell $A$1

Result sheet image

The formulas in result_master.xls will change over time, so I wanted to be able to update them in one place rather than update the formulas in each of the 60+ user_results_sheet workbooks that will be distributed all over the company network.

my 1st attempt

=VLOOKUP($A$1,[result_master.xlsx]Sheet1!$A$1:$B$4,2,FALSE)

returned 0(zero), as it applies the formula to the (results_master) workbook

I need it to apply the formula to the (user_result_sheet) workbook

I tried using different combinations of LEFT,MID, and TRIM to remove the reference to the workbook/sheetname but even when that returned the correct part of the formula, it was as a string and then wouldn't calculate.

2
A User Defined function (aka VBA) could read the underlying formula and apply it to the new worksheet.user4039065
@pnuts: Yes, you may!Jean-François Corbett

2 Answers

3
votes

I would use Named Formulas (Defined Names) to store your formulas in one place and then use CHOOSE to select which named formula to return.
CHOOSE uses a number as its first argument so you could use MATCH to convert your formula word choice to a number.

2
votes

You could write a single VBA user defined function:

Function Eval(s As String) As Variant
    Application.Volatile
    Eval = Application.Evaluate(s)
End Function

then use it like this:

In Sheet1 (note the absence of the leading equals sign):

enter image description here

Then in Sheet2:

enter image description here

With the formula =eval(VLOOKUP(Sheet2!A4,Sheet1!$A$1:$B$4,2,FALSE)) entered into B4 and copied down.