Formula Errors

Use MATCH to Reference the Last Used Row in Another Excel Workbook

Khadija KhanKhadija Khan Nov 25, 2026 869 views

Question details

Create a VBA-generated MATCH formula that searches column B through its last used row in another workbook.

Use MATCH to Reference the Last Used Row in Another Excel Workbook
Product
Microsoft Excel
Device & OS
not provided
Scenario
A VBA procedure writes a MATCH formula in one workbook using data from Sheet1 in another open workbook.
Observed behavior
The existing formula returns a #NAME? error instead of evaluating the external reference.
Before you start

Open both workbooks and confirm the source workbook's exact file name, extension, and worksheet name. Identify the destination cell and the cell containing the value to match.

Solution 1Recommended

Build the External MATCH Reference with VBA

Use the source worksheet to calculate the last row, then insert that row number into the formula string.

The example assumes the macro is stored in the destination workbook, the lookup value is in D3, and the formula belongs in E3. Replace the workbook, sheet, and cell names with your own.

1
Open the VBA editor

In Excel, open the VBA editor from Developer > Visual Basic, then open the procedure that writes the formula.

2
Calculate the source row

In the procedure, qualify the source workbook and worksheet: Dim src As Worksheet, lastRow As Long Set src = Workbooks("newfsimacro.xlsx").Worksheets("Sheet1") lastRow = src.Cells(src.Rows.Count, "B").End(xlUp).Row

3
Write the MATCH formula

Add this line to write the formula to the destination sheet: ThisWorkbook.Worksheets("Sheet1").Range("E3").Formula = "=MATCH(D3,'[newfsimacro.xlsx]Sheet1'!$B$1:$B$" & lastRow & ",0)"

4
Run and check the result

Run the procedure from the VBA editor, then select E3 and inspect the formula bar. Confirm that the external workbook name, sheet name, and final row number are correct.

Build the External MATCH Reference with VBA
The row number is fixed when the macro runs: The formula uses the last row calculated at insertion time. Run the procedure again if the source data grows or shrinks.
Free Microsoft Office alternative

Work with MATCH Formulas in WPS Spreadsheets

WPS Office is a free, lightweight, easy-to-use alternative for working with spreadsheets. Its familiar interface and Excel format compatibility make it convenient to move existing files into WPS, though it does not fix Excel's VBA behavior.

Use MATCH formulas to find values in spreadsheet rangesOpen and edit Microsoft Excel XLSX and XLS filesNavigate a familiar spreadsheet interfaceMove existing Office documents into a lightweight suite
microsoft office alternative - wps office

Frequently Asked Questions

Why does my external MATCH formula show #NAME?

Check the formula bar for an unrecognized function or malformed reference. In VBA, concatenate the row variable outside the quoted formula string, and include the correct workbook name and extension.

Does the source workbook need to be open?

Yes, for the VBA example shown here: Workbooks("newfsimacro.xlsx") identifies an open workbook. Open the source file before running the procedure.

Will the formula expand automatically when new rows are added?

No. The macro inserts the last row number it calculates at that moment. Run the procedure again to update the range after the source data changes.

What does #N/A mean after the formula is fixed?

With MATCH's third argument set to 0, #N/A means Excel did not find an exact match in the specified range. Check D3 and the values in the source column B.