Fix VLOOKUP from Another Workbook Using Dynamic Cell References
Question details
The user is attempting to perform a VLOOKUP targeting a separate workbook using dynamically constructed cell references, but encounters a #VALUE! error.

- Product
- Spreadsheet
- Device & OS
- not provided
- Scenario
- Constructing dynamic references utilizing a workbook path, sheet name, and cell range stored in other cells to execute a VLOOKUP without hard-coding the data source.
- Observed behavior
- A hard-coded VLOOKUP works fine, but the dynamic formula returns #VALUE!. Attempted custom VBA functions also fail due to undefined workbook objects or invalid range arguments.
Verify the exact file path, worksheet name, and range of your external data source. Note that standard dynamic referencing functions like INDIRECT will fail if the target workbook is closed.
Use a Custom VBA Function to Open the Source Workbook
Because standard dynamic functions fail on closed workbooks, writing a custom VBA macro to temporarily open the workbook, execute the VLOOKUP, and close it is the most robust approach.
The built-in WorksheetFunction.VLookup in VBA generally requires the source workbook to be open in the background to calculate properly.
By passing explicit arguments to your custom function, defining the workbook object, and forcing the file to open briefly, you avoid #VALUE! errors.
Press Alt + F11 in your spreadsheet to open the Visual Basic for Applications (VBA) editor.
Click 'Insert' > 'Module' to create a blank script window where you will define the custom VLOOKUP function.
Write a function such as 'Function GetMyVal(lookupVal, filePath, sheetName, rangeStr)'. Inside the function, add 'Set wb = Workbooks.Open(filePath)' to explicitly define the workbook object and open the external file.
Set your lookup range using 'wb.Worksheets(sheetName).Range(rangeStr)'. Call 'Application.WorksheetFunction.VLookup' to fetch the value, and then close the source workbook immediately using 'wb.Close False'.
Return to your worksheet and type your new custom formula. Ensure your arguments are formatted correctly as text, for example: =GetMyVal(A1, "C:\Data.xlsx", "Sheet1", "D1:G200").

Use the INDIRECT Function (Requires Open Workbooks)
If you do not want to use VBA and are willing to keep the source workbook open while working, you can use the built-in INDIRECT function to piece together dynamic reference paths.
Efficiently Handle Complex Formulas and VBA with WPS Spreadsheet
WPS Spreadsheet provides powerful support for dynamic cell referencing, advanced functions like VLOOKUP and INDIRECT, and robust VBA macro execution to help you manage data across multiple workbooks flawlessly.
- 1. Download and Install: Download WPS Office for free from the official website and install it on your computer.
- 2. Open Your Spreadsheets: Open both your primary worksheet and the external data workbook simultaneously using the intuitive tabbed interface.
- 3. Apply Dynamic Functions: Utilize built-in functions like INDIRECT and VLOOKUP exactly as you would in standard spreadsheet software.
- 4. Run Custom VBA: Access the Developer tab to open the VBA Editor, allowing you to quickly copy in custom macro functions for closed workbooks.

Frequently Asked Questions
Why does my dynamic VLOOKUP formula return a #VALUE! or #REF! error?
This commonly happens when using the INDIRECT function to dynamically reference another workbook that is currently closed. INDIRECT requires the target workbook to be actively open in the background to evaluate the string correctly.
Can I use the INDIRECT function with closed workbooks?
No, the built-in INDIRECT function works exclusively with open workbooks. If you need to retrieve data from a closed workbook dynamically, you must use a custom VBA script or the specialized Excel/WPS add-ins designed for closed workbook queries.
Why does my custom VBA WorksheetFunction.VLookup fail on execution?
It generally fails if the workbook object (such as 'wb') is undefined, or if the referenced source workbook hasn't been explicitly opened in the code. You must use 'Workbooks.Open' to load the file into memory before executing the lookup range evaluation.
What does a volatile function mean in a spreadsheet?
A volatile function, such as INDIRECT, TODAY, or OFFSET, recalculates automatically every time any cell in the entire workbook is changed or refreshed. Using too many volatile VLOOKUP formulas can severely slow down calculation performance.




