I want to refer to a cell value in another closed workbook with a formula (not VBA!). The Sheet name is stored as a variable (in the following example, C13 is "Sheet2").
If the other file is open, then following works:
=INDIRECT("[myExcelFile.xlsm]" & C13 & "!$A$1")
If the file is closed, the above formula doesn't work, as there is no absolute path given. But I got it work with following (give attention to ' instead of ":
='C:\data\[myExcelFile.xlsm]Sheet2'!$A$1
Now I want to replace the hardcoded "Sheet2" with a dynamic referenced value, means with C13 (as seen in the first code snippet).
Does anybody know a solution without using VBA or other libraries?
There is definitively no way to do this with standard formulas. However, a crazy sort of answer can be found here. It still avoids VBA, and it will allow you to get your result dynamically.
First, make the formula that will generate your formula, but don't add the = at the beginning!
Let us pretend that you have created this formula in cell B2 of Sheet1, and you would like the formula to be evaluated in column c.
Now, go to the Formulas tab, and choose "Define Name". Give it the name myResult (or whatever you choose), and under Refers To, write =evaluate(Sheet1!$B2) (note the $)
Finally, go to C2, and write =myResult. Drag down, and... voila!
I too was looking for the answer to referencing cells in a closed workbook. Here is the link to the solution (correct formula) below. I have tried it on my current project (referencing a single cell and an array of cells) and it works well with no errors. I hope it helps you.
https://www.extendoffice.com/documents/excel/4226-excel-reference-unopened-file.html
In the formula, E:\Excel file\ is the full file path of the unopened workbook, test.xlsx is the name of the workbook, Sheet2 is the sheet name which contains the cell value you need to reference from, and A:A,2,1 means the cell A2 will be referenced in the closed workbook. You can change them based on your needs.
If you want to manually select a worksheet to reference, please use this formula
=INDEX('E:\Excel file\[test.xlsx]sheetname'!A:A,2,1)
After applying this formula, you will get a Select Sheet dialog box, please select a worksheet and then click the OK button. Then the certain cell value of this worksheet will be referenced immediately.
The problem is that a link to a closed file works with index( but not with index(indirect(
It seems to me that it is a programming issue of the index function.
I solved it with a if clause row
C2=sheetname
if(c2=Sheet1,index(sheet1....),if(C2="Sheet2",index(sheet2....
I did it over five sheets, it's a long formula, but does what I need.
Check INDEX Function:
=INDEX('C:\path\[file.xlsm]Sheet1'!A10:B20;1;1)
Thank you for the great question. I want to clarify and second the solution posted by Philipp. The solution does the following:
Updates data from a closed Excel file, and
Does so "dynamically" (though not exactly - you'll see)
In his answer above, Philipp said: "The problem is that a link to a closed file works with index( but not with index(indirect("
I believe this is still true. (I'm using Office 365 here in March of 2021. It would be so nice if Microsoft allowed INDIRECT and INDEX to play nicely together with closed files!)
I can confirm that Philipp's workaround indeed works, practically speaking. From the user's point of view, it feels like what Chris, the OP, wants to do.
Let's say you want the contents of a given cell to be drawn from Sheet1, Sheet2 or Sheet3, which are from a closed file myExcelFile.xlsm. You will choose which sheet by changing the contents of a particular cell (C13, as in the OP Chris's question). One way to do this is to make it a drop-down list (using Data > Data Validation > Allow [List]). The list will have the following names:
Sheet1
Sheet2
Sheet3
(This will generalize without the drop-down list. For example, you can just type "Sheet2" into C13, and the relevant data from the closed file will appear; if you then type "Sheet3" then the data from that sheet will appear instead. Or you can have a column with the sheet names, and the next column over [with the formula below, adjusted] for the output from the closed file.)
The cell that will contain the referenced data from the other, closed sheet (myExcelFile.xlsm) will have:
=IFS(
C13="Sheet1",'C:\data\[myExcelFile.xlsm]Sheet1'!$A$1,
C13="Sheet2",'C:\data\[myExcelFile.xlsm]Sheet2'!$A$1,
C13="Sheet3",'C:\data\[myExcelFile.xlsm]Sheet3'!$A$1
)
And that's it.
It'll throw up a #REF error the first time you do this with myExcelFile.xlsm closed, but you can go to Data > Queries & Connections > Edit Links > Update Values and your values from the closed file should appear. (Personally, I set up a macro with a button to do the updating, instead of hunting through the menus.) The magic is that when you do Update Values, the data from all of the sheets in the closed file get loaded into the current Excel file - so you don't have to update every time you switch the reference to a different sheet (Sheet2 to Sheet3, for example).
Andrew
In Excel 2016 at least, you can use INDIRECT with a full path reference; the entire reference (including sheet name) needs to be enclosed by ' characters.
So this should work for you:
= INDIRECT("'C:\data\[myExcelFile.xlsm]" & C13 & "'!$A$1")
Note the closing ' in the last string (ie '!$A$1 surrounded by "")
=INDIRECT("'C:\Data["&A8&"]SheetNAME'!$G9")
where A8 contains myExcelFile.xlsm
and G9 contains your source workbook precious data.
OK,
Here's a dinosaur method for you on Office 2010.
Write the full address you want using concatenate (the "&" method of combining text).
Do this for all the addresses you need. It should look like:
="="&"'\FULL NETWORK ADDRESS including [Spreadsheet Name]"&W3&"'!$w4"
The W3 is a dynamic reference to what sheet I am using, the W4 is the cell I want to get from the sheet.
Once you have this, start up a macro recording session. Copy the cell and paste it into another. I pasted it into a merged cell and it gave me the classic "Same size" error. But one thing it did was paste the resulting text from my concatenate (including that extra "=").
Copy over however many you did this for. Then, go into each pasted cell, select he text and just hit enter. It updates it to an active direct reference.
Once you have finished, put the cursor somewhere nice and stop the macro. Assign it to a button and you are done.
It is a bit of a PITA to do this the first time, but once you have done it, you have just made the square peg fit that daamned round hole.
This seems to work with closed file: add a pivot table (rows, tabular layout, no subtotals, no grand totals) of the source to the current workbook, then reference all you want from that pivot table, INDIRECT, LOOKUPs,...
If you know the number of sheet you want to reference you can use below function to find out the name. Than you can use it in INDIRECT funcion.
Public Function GETSHEETNAME(address As String, Optional SheetNumber As Integer = 1) As String
Set WS = GetObject(address).Worksheets
GETSHEETNAME = WS(SheetNumber).Name
End Function
This solution doesn't require referenced workbook to be open - Excel gonna open it by itself (but it's gonna be hidden).
I was disappointed so I made the following workaround:
I created my INDIRECT commands and stored them just outside the desired range. Of course I get errors when the source workbook is closed but they light up when it's open.
So I open the source workbook temporarily.
Then I created a macro that copies the INDIRECT formulas from outside the range and pastes them inside the range. All cells are filled in with the right values.
The macro then copy-pastes the values of the range to the range on top of themselves. This deletes the formulas but keeps their values.
Then I close the source workbook. My values stay intact where I want them and my INDIRECT formulas stay just outside the desired range in case I want to refresh them by repeating the procedure!
This workaround saves me the error of the indirect formulas when the source workbook is closed, and most importantly it saves a lot of time in recalculations!
Hope this works for you too!
Related
I want to refer to a cell value in another closed workbook with a formula (not VBA!). The Sheet name is stored as a variable (in the following example, C13 is "Sheet2").
If the other file is open, then following works:
=INDIRECT("[myExcelFile.xlsm]" & C13 & "!$A$1")
If the file is closed, the above formula doesn't work, as there is no absolute path given. But I got it work with following (give attention to ' instead of ":
='C:\data\[myExcelFile.xlsm]Sheet2'!$A$1
Now I want to replace the hardcoded "Sheet2" with a dynamic referenced value, means with C13 (as seen in the first code snippet).
Does anybody know a solution without using VBA or other libraries?
There is definitively no way to do this with standard formulas. However, a crazy sort of answer can be found here. It still avoids VBA, and it will allow you to get your result dynamically.
First, make the formula that will generate your formula, but don't add the = at the beginning!
Let us pretend that you have created this formula in cell B2 of Sheet1, and you would like the formula to be evaluated in column c.
Now, go to the Formulas tab, and choose "Define Name". Give it the name myResult (or whatever you choose), and under Refers To, write =evaluate(Sheet1!$B2) (note the $)
Finally, go to C2, and write =myResult. Drag down, and... voila!
I too was looking for the answer to referencing cells in a closed workbook. Here is the link to the solution (correct formula) below. I have tried it on my current project (referencing a single cell and an array of cells) and it works well with no errors. I hope it helps you.
https://www.extendoffice.com/documents/excel/4226-excel-reference-unopened-file.html
In the formula, E:\Excel file\ is the full file path of the unopened workbook, test.xlsx is the name of the workbook, Sheet2 is the sheet name which contains the cell value you need to reference from, and A:A,2,1 means the cell A2 will be referenced in the closed workbook. You can change them based on your needs.
If you want to manually select a worksheet to reference, please use this formula
=INDEX('E:\Excel file\[test.xlsx]sheetname'!A:A,2,1)
After applying this formula, you will get a Select Sheet dialog box, please select a worksheet and then click the OK button. Then the certain cell value of this worksheet will be referenced immediately.
The problem is that a link to a closed file works with index( but not with index(indirect(
It seems to me that it is a programming issue of the index function.
I solved it with a if clause row
C2=sheetname
if(c2=Sheet1,index(sheet1....),if(C2="Sheet2",index(sheet2....
I did it over five sheets, it's a long formula, but does what I need.
Check INDEX Function:
=INDEX('C:\path\[file.xlsm]Sheet1'!A10:B20;1;1)
Thank you for the great question. I want to clarify and second the solution posted by Philipp. The solution does the following:
Updates data from a closed Excel file, and
Does so "dynamically" (though not exactly - you'll see)
In his answer above, Philipp said: "The problem is that a link to a closed file works with index( but not with index(indirect("
I believe this is still true. (I'm using Office 365 here in March of 2021. It would be so nice if Microsoft allowed INDIRECT and INDEX to play nicely together with closed files!)
I can confirm that Philipp's workaround indeed works, practically speaking. From the user's point of view, it feels like what Chris, the OP, wants to do.
Let's say you want the contents of a given cell to be drawn from Sheet1, Sheet2 or Sheet3, which are from a closed file myExcelFile.xlsm. You will choose which sheet by changing the contents of a particular cell (C13, as in the OP Chris's question). One way to do this is to make it a drop-down list (using Data > Data Validation > Allow [List]). The list will have the following names:
Sheet1
Sheet2
Sheet3
(This will generalize without the drop-down list. For example, you can just type "Sheet2" into C13, and the relevant data from the closed file will appear; if you then type "Sheet3" then the data from that sheet will appear instead. Or you can have a column with the sheet names, and the next column over [with the formula below, adjusted] for the output from the closed file.)
The cell that will contain the referenced data from the other, closed sheet (myExcelFile.xlsm) will have:
=IFS(
C13="Sheet1",'C:\data\[myExcelFile.xlsm]Sheet1'!$A$1,
C13="Sheet2",'C:\data\[myExcelFile.xlsm]Sheet2'!$A$1,
C13="Sheet3",'C:\data\[myExcelFile.xlsm]Sheet3'!$A$1
)
And that's it.
It'll throw up a #REF error the first time you do this with myExcelFile.xlsm closed, but you can go to Data > Queries & Connections > Edit Links > Update Values and your values from the closed file should appear. (Personally, I set up a macro with a button to do the updating, instead of hunting through the menus.) The magic is that when you do Update Values, the data from all of the sheets in the closed file get loaded into the current Excel file - so you don't have to update every time you switch the reference to a different sheet (Sheet2 to Sheet3, for example).
Andrew
In Excel 2016 at least, you can use INDIRECT with a full path reference; the entire reference (including sheet name) needs to be enclosed by ' characters.
So this should work for you:
= INDIRECT("'C:\data\[myExcelFile.xlsm]" & C13 & "'!$A$1")
Note the closing ' in the last string (ie '!$A$1 surrounded by "")
=INDIRECT("'C:\Data["&A8&"]SheetNAME'!$G9")
where A8 contains myExcelFile.xlsm
and G9 contains your source workbook precious data.
OK,
Here's a dinosaur method for you on Office 2010.
Write the full address you want using concatenate (the "&" method of combining text).
Do this for all the addresses you need. It should look like:
="="&"'\FULL NETWORK ADDRESS including [Spreadsheet Name]"&W3&"'!$w4"
The W3 is a dynamic reference to what sheet I am using, the W4 is the cell I want to get from the sheet.
Once you have this, start up a macro recording session. Copy the cell and paste it into another. I pasted it into a merged cell and it gave me the classic "Same size" error. But one thing it did was paste the resulting text from my concatenate (including that extra "=").
Copy over however many you did this for. Then, go into each pasted cell, select he text and just hit enter. It updates it to an active direct reference.
Once you have finished, put the cursor somewhere nice and stop the macro. Assign it to a button and you are done.
It is a bit of a PITA to do this the first time, but once you have done it, you have just made the square peg fit that daamned round hole.
This seems to work with closed file: add a pivot table (rows, tabular layout, no subtotals, no grand totals) of the source to the current workbook, then reference all you want from that pivot table, INDIRECT, LOOKUPs,...
If you know the number of sheet you want to reference you can use below function to find out the name. Than you can use it in INDIRECT funcion.
Public Function GETSHEETNAME(address As String, Optional SheetNumber As Integer = 1) As String
Set WS = GetObject(address).Worksheets
GETSHEETNAME = WS(SheetNumber).Name
End Function
This solution doesn't require referenced workbook to be open - Excel gonna open it by itself (but it's gonna be hidden).
I was disappointed so I made the following workaround:
I created my INDIRECT commands and stored them just outside the desired range. Of course I get errors when the source workbook is closed but they light up when it's open.
So I open the source workbook temporarily.
Then I created a macro that copies the INDIRECT formulas from outside the range and pastes them inside the range. All cells are filled in with the right values.
The macro then copy-pastes the values of the range to the range on top of themselves. This deletes the formulas but keeps their values.
Then I close the source workbook. My values stay intact where I want them and my INDIRECT formulas stay just outside the desired range in case I want to refresh them by repeating the procedure!
This workaround saves me the error of the indirect formulas when the source workbook is closed, and most importantly it saves a lot of time in recalculations!
Hope this works for you too!
I want to refer to a cell value in another closed workbook with a formula (not VBA!). The Sheet name is stored as a variable (in the following example, C13 is "Sheet2").
If the other file is open, then following works:
=INDIRECT("[myExcelFile.xlsm]" & C13 & "!$A$1")
If the file is closed, the above formula doesn't work, as there is no absolute path given. But I got it work with following (give attention to ' instead of ":
='C:\data\[myExcelFile.xlsm]Sheet2'!$A$1
Now I want to replace the hardcoded "Sheet2" with a dynamic referenced value, means with C13 (as seen in the first code snippet).
Does anybody know a solution without using VBA or other libraries?
There is definitively no way to do this with standard formulas. However, a crazy sort of answer can be found here. It still avoids VBA, and it will allow you to get your result dynamically.
First, make the formula that will generate your formula, but don't add the = at the beginning!
Let us pretend that you have created this formula in cell B2 of Sheet1, and you would like the formula to be evaluated in column c.
Now, go to the Formulas tab, and choose "Define Name". Give it the name myResult (or whatever you choose), and under Refers To, write =evaluate(Sheet1!$B2) (note the $)
Finally, go to C2, and write =myResult. Drag down, and... voila!
I too was looking for the answer to referencing cells in a closed workbook. Here is the link to the solution (correct formula) below. I have tried it on my current project (referencing a single cell and an array of cells) and it works well with no errors. I hope it helps you.
https://www.extendoffice.com/documents/excel/4226-excel-reference-unopened-file.html
In the formula, E:\Excel file\ is the full file path of the unopened workbook, test.xlsx is the name of the workbook, Sheet2 is the sheet name which contains the cell value you need to reference from, and A:A,2,1 means the cell A2 will be referenced in the closed workbook. You can change them based on your needs.
If you want to manually select a worksheet to reference, please use this formula
=INDEX('E:\Excel file\[test.xlsx]sheetname'!A:A,2,1)
After applying this formula, you will get a Select Sheet dialog box, please select a worksheet and then click the OK button. Then the certain cell value of this worksheet will be referenced immediately.
The problem is that a link to a closed file works with index( but not with index(indirect(
It seems to me that it is a programming issue of the index function.
I solved it with a if clause row
C2=sheetname
if(c2=Sheet1,index(sheet1....),if(C2="Sheet2",index(sheet2....
I did it over five sheets, it's a long formula, but does what I need.
Check INDEX Function:
=INDEX('C:\path\[file.xlsm]Sheet1'!A10:B20;1;1)
Thank you for the great question. I want to clarify and second the solution posted by Philipp. The solution does the following:
Updates data from a closed Excel file, and
Does so "dynamically" (though not exactly - you'll see)
In his answer above, Philipp said: "The problem is that a link to a closed file works with index( but not with index(indirect("
I believe this is still true. (I'm using Office 365 here in March of 2021. It would be so nice if Microsoft allowed INDIRECT and INDEX to play nicely together with closed files!)
I can confirm that Philipp's workaround indeed works, practically speaking. From the user's point of view, it feels like what Chris, the OP, wants to do.
Let's say you want the contents of a given cell to be drawn from Sheet1, Sheet2 or Sheet3, which are from a closed file myExcelFile.xlsm. You will choose which sheet by changing the contents of a particular cell (C13, as in the OP Chris's question). One way to do this is to make it a drop-down list (using Data > Data Validation > Allow [List]). The list will have the following names:
Sheet1
Sheet2
Sheet3
(This will generalize without the drop-down list. For example, you can just type "Sheet2" into C13, and the relevant data from the closed file will appear; if you then type "Sheet3" then the data from that sheet will appear instead. Or you can have a column with the sheet names, and the next column over [with the formula below, adjusted] for the output from the closed file.)
The cell that will contain the referenced data from the other, closed sheet (myExcelFile.xlsm) will have:
=IFS(
C13="Sheet1",'C:\data\[myExcelFile.xlsm]Sheet1'!$A$1,
C13="Sheet2",'C:\data\[myExcelFile.xlsm]Sheet2'!$A$1,
C13="Sheet3",'C:\data\[myExcelFile.xlsm]Sheet3'!$A$1
)
And that's it.
It'll throw up a #REF error the first time you do this with myExcelFile.xlsm closed, but you can go to Data > Queries & Connections > Edit Links > Update Values and your values from the closed file should appear. (Personally, I set up a macro with a button to do the updating, instead of hunting through the menus.) The magic is that when you do Update Values, the data from all of the sheets in the closed file get loaded into the current Excel file - so you don't have to update every time you switch the reference to a different sheet (Sheet2 to Sheet3, for example).
Andrew
In Excel 2016 at least, you can use INDIRECT with a full path reference; the entire reference (including sheet name) needs to be enclosed by ' characters.
So this should work for you:
= INDIRECT("'C:\data\[myExcelFile.xlsm]" & C13 & "'!$A$1")
Note the closing ' in the last string (ie '!$A$1 surrounded by "")
=INDIRECT("'C:\Data["&A8&"]SheetNAME'!$G9")
where A8 contains myExcelFile.xlsm
and G9 contains your source workbook precious data.
OK,
Here's a dinosaur method for you on Office 2010.
Write the full address you want using concatenate (the "&" method of combining text).
Do this for all the addresses you need. It should look like:
="="&"'\FULL NETWORK ADDRESS including [Spreadsheet Name]"&W3&"'!$w4"
The W3 is a dynamic reference to what sheet I am using, the W4 is the cell I want to get from the sheet.
Once you have this, start up a macro recording session. Copy the cell and paste it into another. I pasted it into a merged cell and it gave me the classic "Same size" error. But one thing it did was paste the resulting text from my concatenate (including that extra "=").
Copy over however many you did this for. Then, go into each pasted cell, select he text and just hit enter. It updates it to an active direct reference.
Once you have finished, put the cursor somewhere nice and stop the macro. Assign it to a button and you are done.
It is a bit of a PITA to do this the first time, but once you have done it, you have just made the square peg fit that daamned round hole.
This seems to work with closed file: add a pivot table (rows, tabular layout, no subtotals, no grand totals) of the source to the current workbook, then reference all you want from that pivot table, INDIRECT, LOOKUPs,...
If you know the number of sheet you want to reference you can use below function to find out the name. Than you can use it in INDIRECT funcion.
Public Function GETSHEETNAME(address As String, Optional SheetNumber As Integer = 1) As String
Set WS = GetObject(address).Worksheets
GETSHEETNAME = WS(SheetNumber).Name
End Function
This solution doesn't require referenced workbook to be open - Excel gonna open it by itself (but it's gonna be hidden).
I was disappointed so I made the following workaround:
I created my INDIRECT commands and stored them just outside the desired range. Of course I get errors when the source workbook is closed but they light up when it's open.
So I open the source workbook temporarily.
Then I created a macro that copies the INDIRECT formulas from outside the range and pastes them inside the range. All cells are filled in with the right values.
The macro then copy-pastes the values of the range to the range on top of themselves. This deletes the formulas but keeps their values.
Then I close the source workbook. My values stay intact where I want them and my INDIRECT formulas stay just outside the desired range in case I want to refresh them by repeating the procedure!
This workaround saves me the error of the indirect formulas when the source workbook is closed, and most importantly it saves a lot of time in recalculations!
Hope this works for you too!
I want to refer to a cell value in another closed workbook with a formula (not VBA!). The Sheet name is stored as a variable (in the following example, C13 is "Sheet2").
If the other file is open, then following works:
=INDIRECT("[myExcelFile.xlsm]" & C13 & "!$A$1")
If the file is closed, the above formula doesn't work, as there is no absolute path given. But I got it work with following (give attention to ' instead of ":
='C:\data\[myExcelFile.xlsm]Sheet2'!$A$1
Now I want to replace the hardcoded "Sheet2" with a dynamic referenced value, means with C13 (as seen in the first code snippet).
Does anybody know a solution without using VBA or other libraries?
There is definitively no way to do this with standard formulas. However, a crazy sort of answer can be found here. It still avoids VBA, and it will allow you to get your result dynamically.
First, make the formula that will generate your formula, but don't add the = at the beginning!
Let us pretend that you have created this formula in cell B2 of Sheet1, and you would like the formula to be evaluated in column c.
Now, go to the Formulas tab, and choose "Define Name". Give it the name myResult (or whatever you choose), and under Refers To, write =evaluate(Sheet1!$B2) (note the $)
Finally, go to C2, and write =myResult. Drag down, and... voila!
I too was looking for the answer to referencing cells in a closed workbook. Here is the link to the solution (correct formula) below. I have tried it on my current project (referencing a single cell and an array of cells) and it works well with no errors. I hope it helps you.
https://www.extendoffice.com/documents/excel/4226-excel-reference-unopened-file.html
In the formula, E:\Excel file\ is the full file path of the unopened workbook, test.xlsx is the name of the workbook, Sheet2 is the sheet name which contains the cell value you need to reference from, and A:A,2,1 means the cell A2 will be referenced in the closed workbook. You can change them based on your needs.
If you want to manually select a worksheet to reference, please use this formula
=INDEX('E:\Excel file\[test.xlsx]sheetname'!A:A,2,1)
After applying this formula, you will get a Select Sheet dialog box, please select a worksheet and then click the OK button. Then the certain cell value of this worksheet will be referenced immediately.
The problem is that a link to a closed file works with index( but not with index(indirect(
It seems to me that it is a programming issue of the index function.
I solved it with a if clause row
C2=sheetname
if(c2=Sheet1,index(sheet1....),if(C2="Sheet2",index(sheet2....
I did it over five sheets, it's a long formula, but does what I need.
Check INDEX Function:
=INDEX('C:\path\[file.xlsm]Sheet1'!A10:B20;1;1)
Thank you for the great question. I want to clarify and second the solution posted by Philipp. The solution does the following:
Updates data from a closed Excel file, and
Does so "dynamically" (though not exactly - you'll see)
In his answer above, Philipp said: "The problem is that a link to a closed file works with index( but not with index(indirect("
I believe this is still true. (I'm using Office 365 here in March of 2021. It would be so nice if Microsoft allowed INDIRECT and INDEX to play nicely together with closed files!)
I can confirm that Philipp's workaround indeed works, practically speaking. From the user's point of view, it feels like what Chris, the OP, wants to do.
Let's say you want the contents of a given cell to be drawn from Sheet1, Sheet2 or Sheet3, which are from a closed file myExcelFile.xlsm. You will choose which sheet by changing the contents of a particular cell (C13, as in the OP Chris's question). One way to do this is to make it a drop-down list (using Data > Data Validation > Allow [List]). The list will have the following names:
Sheet1
Sheet2
Sheet3
(This will generalize without the drop-down list. For example, you can just type "Sheet2" into C13, and the relevant data from the closed file will appear; if you then type "Sheet3" then the data from that sheet will appear instead. Or you can have a column with the sheet names, and the next column over [with the formula below, adjusted] for the output from the closed file.)
The cell that will contain the referenced data from the other, closed sheet (myExcelFile.xlsm) will have:
=IFS(
C13="Sheet1",'C:\data\[myExcelFile.xlsm]Sheet1'!$A$1,
C13="Sheet2",'C:\data\[myExcelFile.xlsm]Sheet2'!$A$1,
C13="Sheet3",'C:\data\[myExcelFile.xlsm]Sheet3'!$A$1
)
And that's it.
It'll throw up a #REF error the first time you do this with myExcelFile.xlsm closed, but you can go to Data > Queries & Connections > Edit Links > Update Values and your values from the closed file should appear. (Personally, I set up a macro with a button to do the updating, instead of hunting through the menus.) The magic is that when you do Update Values, the data from all of the sheets in the closed file get loaded into the current Excel file - so you don't have to update every time you switch the reference to a different sheet (Sheet2 to Sheet3, for example).
Andrew
In Excel 2016 at least, you can use INDIRECT with a full path reference; the entire reference (including sheet name) needs to be enclosed by ' characters.
So this should work for you:
= INDIRECT("'C:\data\[myExcelFile.xlsm]" & C13 & "'!$A$1")
Note the closing ' in the last string (ie '!$A$1 surrounded by "")
=INDIRECT("'C:\Data["&A8&"]SheetNAME'!$G9")
where A8 contains myExcelFile.xlsm
and G9 contains your source workbook precious data.
OK,
Here's a dinosaur method for you on Office 2010.
Write the full address you want using concatenate (the "&" method of combining text).
Do this for all the addresses you need. It should look like:
="="&"'\FULL NETWORK ADDRESS including [Spreadsheet Name]"&W3&"'!$w4"
The W3 is a dynamic reference to what sheet I am using, the W4 is the cell I want to get from the sheet.
Once you have this, start up a macro recording session. Copy the cell and paste it into another. I pasted it into a merged cell and it gave me the classic "Same size" error. But one thing it did was paste the resulting text from my concatenate (including that extra "=").
Copy over however many you did this for. Then, go into each pasted cell, select he text and just hit enter. It updates it to an active direct reference.
Once you have finished, put the cursor somewhere nice and stop the macro. Assign it to a button and you are done.
It is a bit of a PITA to do this the first time, but once you have done it, you have just made the square peg fit that daamned round hole.
This seems to work with closed file: add a pivot table (rows, tabular layout, no subtotals, no grand totals) of the source to the current workbook, then reference all you want from that pivot table, INDIRECT, LOOKUPs,...
If you know the number of sheet you want to reference you can use below function to find out the name. Than you can use it in INDIRECT funcion.
Public Function GETSHEETNAME(address As String, Optional SheetNumber As Integer = 1) As String
Set WS = GetObject(address).Worksheets
GETSHEETNAME = WS(SheetNumber).Name
End Function
This solution doesn't require referenced workbook to be open - Excel gonna open it by itself (but it's gonna be hidden).
I was disappointed so I made the following workaround:
I created my INDIRECT commands and stored them just outside the desired range. Of course I get errors when the source workbook is closed but they light up when it's open.
So I open the source workbook temporarily.
Then I created a macro that copies the INDIRECT formulas from outside the range and pastes them inside the range. All cells are filled in with the right values.
The macro then copy-pastes the values of the range to the range on top of themselves. This deletes the formulas but keeps their values.
Then I close the source workbook. My values stay intact where I want them and my INDIRECT formulas stay just outside the desired range in case I want to refresh them by repeating the procedure!
This workaround saves me the error of the indirect formulas when the source workbook is closed, and most importantly it saves a lot of time in recalculations!
Hope this works for you too!
I know the formula for inserting the filename, however the file is e.g 54321 Cost Data and I just require to insert the 54321.
Is it possible to insert into a cell the first five characters of the filename?
Please try:
=MID(CELL("filename"),FIND("[",CELL("filename"))+1,5)
.
#barry houdini has kindly pointed out that the above is flawed (in a way that may not often be an issue but could at times be very confusing):
It's better to use a cell reference in CELL function with this formula, e.g. =MID(CELL("filename",A1),FIND("[",CELL("filename",A1))+1,5) - that ensures that the filename used in the formula is the same as the filename where the sheet resides. If you don't do that, and you go in to another workbook and change a cell in that workbook your formula may return a different result, i.e. based on the name of the 2nd workbook.
The syntax for CELL is:
CELL(info_type, [reference])
reference Optional. The cell that you want information about. If omitted, the information specified in the info_type argument is returned for the last cell that was changed.
So 'my' formula should work when first placed in a cell. Might still be working when that cell is next viewed. All seems in order - until the day the displayed value is different and not as a result of any change to the workbook the cell is in. Such behaviour is not what I would describe as 'conventional' for Excel. Even if the last cell that was changed was in a different workbook the cell giving me the value I expect for this workbook may change what is displays.
So better to 'play safe', do as #barry suggests (as always!) and add the 'optional' reference.
How does one cell obtain the formula of another cell as text without using VBA? I can see this question has already been asked many times and the answer is always to write a custom function in VBA.
However, I found a post made in 2006 which claimed to have found the non-VBA solution but the link provided in that post is already broken.
=FormulaText(Reference) will do the trick Documentation
There is nice way of doing this without VBA. It uses XL4 macros (these are macros, but it is not VBA, as asked).
With reference to the figure 1, cells A2:A4 contain usual formulas.
Going to Formulas -> Define Name, I defined two named ranges (see fig. 2), with the information shown in cells A6:B8.
Enter in cell B2 =FormulaAsText. This will retrieve the formula in cell A2 as text.
Explanation:
The named range FormulaAsText uses =GET.CELL(info_type,reference). In this case, ìnfo_type = 6 retrieves the formula, and reference = OFFSET(INDIRECT("RC",FALSE),0,-1) uses the cell with 0 rows and -1 columns offset from the one the formula is used in.
Copy B2 and paste into B3:B4. This will show formulas in A3:A4. Cell A4 shows that the worksheet function CELL only retrieves values, not formulas (as opposed to GET.CELL).
Since FormulaAsText gets the formula from a cell at fixed offset (0,-1) from the current, I defined another range FormulaAsText2, which uses an offset (rows,cols) read from the worksheet itself. Cells D2:D4 contain =FormulaAsText2. Thus, cell D2 shows the contents of cell B3 (=OffSET(D2,1,-2)), which is FormulaAsText. cells D3:D4 show the contents of themselves. This adds some flexibility. YMMV.
PS1: The essence was taken from
http://www.mrexcel.com/forum/excel-questions/20611-info-only-get-cell-arguments.html
PS2: Tim Williams mentioned in a comment "the old XLM GET.FORMULA()". This answer is possibly related (not the same, since this one uses GET.CELL()).
PS3: A simple VBA solution is given, e.g., in
http://dmcritchie.mvps.org/excel/formula.htm
EDIT: Complementing this nice answer, the worksheet function FormulaText is available for Excel 2013 and later.
This suggestion may be helpful for those who after retrieving a block of formulas and transporting them to a new spreadsheet want to put them to work again. Excels FORMULATEXT function is great for picking up formulas but it leaves them as unusable text strings. If you want to get them back as fully functioning formulas you have to edit each one individually to remove the string character, but here is a shortcut for larger blocks.
Get to the position where you have the required formulas as text (in other words after using FORMULATEXT - you have done a copy and (value only) paste). The next step involves highlighting all the cells you want to convert and then navigating to the [Text-To-Columns] menu option ({Data} bar on Excel 2016). You can select 'Delimited' but on the next screen just make sure you de-select any marks that do appear in your formulas. Then 'Finish'. Excel should automatically analyse the cells as containing formulas and you should now have them working again.
There is a way to do this. In my example I had a table that showed a date. The date comes from Sheet!G91. In my table I also had a column that showed the sheet name. I added two more columns to my table. The first column had column(Sheet!g91), which returns the number 7, because G is the seventh letter in the alphabet. I then converted the number to a letter (G) using another table in my workbook. In the second column that I added, I made a formula row(Sheet!G91), which returns the number 91. Note: Row and Column may appear as volatile formulas, which recalculate with every calculation of the workbook.
I wanted another column to show the formula contents of the date cell mentioned at the beginning of this post. I included the following string function (you can also use CONCATENATE).
"=" & AJ9 & "!" & AM9 & AN9
The items separated by ampersands get strung together (that is, concatenated). AJ9 in my example contains the sheet name, AM9 contains the column letter, and AN9 contains the row number.
I now have a column that dynamically updates its contents to reflect the sheet name and cell reference. The results in my workbook cell are
=Sheet!G91.
You can't. This is most likely a design choice to eliminate an average Excel user from accidentally getting something they did not want.
What you are reading is correct - writing a UDF is the solution you want.