Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing value in a closed Excel workbook using INDIRECT?

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?

like image 569
Chris Avatar asked Feb 11 '15 18:02

Chris


People also ask

Does indirect work with a closed workbook?

INDIRECT unfortunately only works with within the workbook or with workbooks that are open during the calculation time. If the external workbook is closed, it will result in a #REF!

Can you reference a closed workbook Excel?

In the Insert File at Cursor dialog box, click the Browse button. 3. In the Select a file to be inserted at the cell cursor position dialog box, find and select the closed workbook you want to reference, and then press the Open button.

How do you use indirect function to reference another workbook in Excel?

The Indirect formula that refers to a different Excel workbook is based on the same approach as a reference to another spreadsheet. You just have to specify the workbook's name is addition to the sheet name and cell address.

How do you value a closed workbook?

In a cell type the equals symbol ( = ), click on a cell in another workbook, then press return. The formula will look something like this. When you close the linked file the address will change to include the full file path of the linked file.


2 Answers

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.

  1. First, make the formula that will generate your formula, but don't add the = at the beginning!

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

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

  4. Finally, go to C2, and write =myResult. Drag down, and... voila!

like image 61
Ben I. Avatar answered Oct 23 '22 06:10

Ben I.


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.

like image 25
Tiffany Avatar answered Oct 23 '22 04:10

Tiffany