Formula to use File path stored in a cell

Deadly 提交于 2020-01-07 09:15:11

问题


I have a Cell A1 on a sheet named 'Settings' with the following file path:

C:\Users\Arun Victor\Documents\New folder\MASTER.xlsm

Sheet1 on the same Workbook has a bunch of cells linked to various cells in MASTER.xlsm like the one shown below:

='C:\Users\Arun Victor\Documents\New folder\[MASTER.xlsm]Employee WOs'!D4

Right now,Whenever there is a change in file path I have to manually edit each and every cell. Instead, I need a formula that uses the File path stored in the common cell A1 and does an operation like this:

='*File path from Sheet-Settings A1* Employee WOs'!D4

回答1:


You're looking for Indirect(). If your cell A1 has the path that you will change (C:\Users\Arun Victor\Documents\New folder\[MASTER.xlsm]).

In your sheet1, those cells which are currently =C:\Users\Arun Victor\Documents\New folder\[MASTER.xlsm]Employee WOs'!D4, can be replaced with =Indirect("'"&A1&"Employee WOs'!D4").

Here's an example. I have a Workbook called "TextBook.xlsx" on my desktop. I want my formula to return the value of whatever cell I want, which I will put in cell C9.

I can change C9 from A1 to B1029 for instance, and D9 will return whatever value that cell has. (in my 'TextBook.xlsx', A1 literally just says "Cell A1".

Note about using Indirect(), you must have the file you're using open, or else you'll get an error. In other words, I have my TextBook.xlsx open, which is why you can see the result ("Cell A1"). If I close the workbook, that will change to a #REF error.




回答2:


In your VBA code, you can use something like:

= Sheet("Settings").Cells(1,1) & "Employee WOs'!D4"  

This way your code will automatically take your changes on cell A1 from your Settings sheet.



来源:https://stackoverflow.com/questions/32076888/formula-to-use-file-path-stored-in-a-cell

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