Is it possible to use Excel functions to evaluate the result of a function?

笑着哭i 提交于 2019-12-08 09:50:22

问题


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.

  1. 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).

  2. 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.

  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!