Function Problems

Fix VLOOKUP from Another Workbook Using Dynamic Cell References

Aamir Naveed AkramAamir Naveed Akram Nov 3, 2026 869 views

Question details

The user is attempting to perform a VLOOKUP targeting a separate workbook using dynamically constructed cell references, but encounters a #VALUE! error.

How to Fix VLOOKUP from Another Workbook Using Dynamic References
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

Press Alt + F11 in your spreadsheet to open the Visual Basic for Applications (VBA) editor.

2
Create a New Module

Click 'Insert' > 'Module' to create a blank script window where you will define the custom VLOOKUP function.

3
Write the Custom 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.

4
Execute VLOOKUP and Close Workbook

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

5
Apply the Function in Your Cell

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 a Custom VBA Function to Open the Source Workbook
Argument Formatting: Ensure you correctly pass typed arguments. Worksheet names and range text (like "D1:G200") must be enclosed in double quotation marks when typed directly into the formula.
Advanced Spreadsheets with WPS Office

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. 1. Download and Install: Download WPS Office for free from the official website and install it on your computer.
  2. 2. Open Your Spreadsheets: Open both your primary worksheet and the external data workbook simultaneously using the intuitive tabbed interface.
  3. 3. Apply Dynamic Functions: Utilize built-in functions like INDIRECT and VLOOKUP exactly as you would in standard spreadsheet software.
  4. 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.
Fully compatible with Microsoft Excel formulas, functions, and cross-workbook data links.Lightweight architecture handles large datasets and multiple open workbooks with ease.Built-in VBA editor (in supported versions) to easily script and run custom VLOOKUP automation.Familiar user interface makes formula troubleshooting and data formatting a seamless experience.
microsoft office alternative - wps office

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.