问题
I have a formula in I2
:
= "=" & "'" & $H2 & $I2 & E2 & "'!" & "$C$2"
It combines the directory, filename, sheet name, and cell location.
Now I'd like to evaluate the result of that formula in J2
. Is it possible to do so without VBA or with just a bit of VBA? I need to be able to fill down I2
to I1000
and I personally prefer a non-VBA approach.
For example, let's say the result of I2
is:
='R:\20180220\[Test.xlsb]'!$C$2
Is there a way to actually show the value of that cell in J2
? Note that workbook Test.xlsb is closed and won't be opened (because I have thousands of workbooks and cannot open all of them).
I tried EVALUATE(Range.Formula)
and ExecuteExcel4Macro()
in VBA, and tried to wrap them with a UDF, but both failed.
回答1:
Here's a kludge that may work for you.
Create the formulas as in your current post. Note that the result in your post lacks a reference to a tab/worksheet --- you likely need to update your formula to include a worksheet. The formula I used in my tests is
= "=" & "'" & $PATH & $FILE & $TAB & "'!" & "$C$2"
(the same as yours but with a field added for the $TAB).Copy/paste special values the results. This replaces
= "=" & "'" & $PATH & $FILE & $TAB & "'!" & "$C$2"
with='C:\PATH\WORKBOOK\TAB!$C$2
to give the correct formulas. Annoyingly they do not calculate automatically.To force an update of the calcs,
F9
doesn't seem to work, so select the results and do a mock find/replace, say replace $C$2 with $C$2. This doesn't change the formulas but gets the recalc going. You might also be able to just save, close and re-open the workbook.
Hope this helps.
来源:https://stackoverflow.com/questions/48892588/is-it-possible-to-use-excel-functions-to-evaluate-the-result-of-a-function