How to Use a Cell Value in an Excel External File Reference
Question details
The user needs to dynamically insert a cell value into an external file reference formula in Excel.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Building dynamic formulas that reference data in other workbooks by reading file names, sheet names, or paths from specific cells.
- Observed behavior
- Normal external references do not natively support inserting a cell value directly, and using the INDIRECT function for this purpose requires the source workbook to remain open.
Verify the exact file path, sheet name, and cell range of the external workbook you intend to reference. Determine whether the source workbook will remain open or closed during use, as this dictates which method you must apply.
Use the INDIRECT Function for Open Workbooks
The INDIRECT function allows you to construct a dynamic reference using cell values, provided the referenced external workbook remains open.
This method is highly effective for dynamically switching between different external files or sheets by changing a single cell value. However, a major limitation of the INDIRECT function is that it will return a #REF! error if the source workbook is closed.
Open both your destination workbook and the source external workbook in Excel.
In your destination workbook, enter the file name or sheet name you want to reference into a specific cell (e.g., cell A1).
Select the cell where you want the external data to appear and construct your formula using concatenation. For example: =INDIRECT("'[" & A1 & ".xlsx]Sheet1'!$B$2").
Press Enter to execute the formula. You can now update the text in cell A1 to dynamically change which external file is referenced without editing the formula itself.
Use a VBA Macro for Closed Workbooks
Since INDIRECT does not support closed workbooks, use a Worksheet_Change VBA macro to dynamically build the file path and update the destination range.
Easily Manage External References with WPS Spreadsheet
WPS Spreadsheet fully supports advanced functions like INDIRECT and robust VBA macros, allowing you to build dynamic external file references effortlessly.
- 1. Open WPS Spreadsheet: Launch WPS Office and open your primary spreadsheet along with any external data files.
- 2. Input Reference Variables: Type the file name, path, or sheet name of your external source into a specific variable cell.
- 3. Apply INDIRECT Formula: Select your destination cell and use the INDIRECT function to dynamically combine the variable cell value with your external file path.
- 4. Automate with Macros: For referencing closed workbooks, navigate to the Developer tab to insert a VBA script that automates the data retrieval process.

Frequently Asked Questions
Why does my INDIRECT formula return a #REF! error when referencing an external file?
The INDIRECT function natively only works with open workbooks. If the external file you are referencing is closed, Excel cannot resolve the dynamic link and will return a #REF! error. To fix this, either keep the source workbook open or use a VBA macro instead.
Can I use the cell value to dynamically change the sheet name in an external reference?
Yes, you can use the INDIRECT function to concatenate a cell value specifically into the sheet name portion of your reference. For example, using =INDIRECT("'[Data.xlsx]" & A2 & "'!$C$5") allows cell A2 to dictate the target sheet name.
Do I need to save my workbook differently if I use VBA for external references?
Yes. If you use a VBA macro to handle external references for closed workbooks, you must save your file as an Excel Macro-Enabled Workbook (.xlsm). Standard .xlsx files cannot store executable VBA code.





