Use MATCH to Reference the Last Used Row in Another Excel Workbook
Question details
Create a VBA-generated MATCH formula that searches column B through its last used row in another 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.
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.
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.
In Excel, open the VBA editor from Developer > Visual Basic, then open the procedure that writes the formula.
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
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)"
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.

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.

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.




