How to Fix MATCH and OFFSET Formula Errors in Excel VBA
Question details
Users encounter runtime errors when executing MATCH or OFFSET functions in VBA against named ranges that span entire rows, or when trying to lookup date formats.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Running a VBA macro utilizing WorksheetFunction.Match or Offset on a full-row named range, or attempting to match a date string against a row of dates.
- Observed behavior
- The macro fails with Error 1004 because offsetting a full-row range exceeds the worksheet boundary, or because the MATCH function fails to recognize standard date strings.
Ensure your Excel named ranges do not unintentionally select entire rows (like 1:1) if you plan to offset them, and verify that the data types in your lookup array match your search criteria.
Specify a Column Property Instead of Offsetting a Full Row
Avoid boundary errors by selecting a specific column directly from the named range rather than offsetting the entire row.
When a named range spans an entire row, using the Offset method by even one column pushes the range beyond Excel's maximum column limit, triggering Runtime Error 1004 in VBA. While this might sometimes work in a standard worksheet formula, VBA is stricter regarding boundaries.
Press ALT + F11 in your spreadsheet to open the Visual Basic for Applications window, then locate the module containing your MATCH or OFFSET code.
Find the line where you are applying an offset to a full row. For example, look for syntax like Range("Macro!$4:$4").Offset(0, 1).
Modify the code to reference a specific column instead. Update your WorksheetFunction to something like: RESULTS = Application.WorksheetFunction.Match(Range("F117"), Range("Macro").Columns(2), 0).

Convert Date Values to Serial Numbers for MATCH
VBA's MATCH function requires dates to be formatted as Excel serial numbers to successfully look up a date value in an array.
Use WPS Office to Run Advanced VBA Macros Seamlessly
WPS Office offers robust and highly compatible support for Excel VBA, allowing you to write, edit, and execute macros with complex WorksheetFunctions like INDEX, MATCH, and OFFSET without unexpected compatibility hurdles.
- 1. Download and Install WPS Office: Get the free WPS Office suite from the official website and complete the quick installation process.
- 2. Open Your Macro-enabled Workbook: Launch WPS Spreadsheet and open your existing Excel file containing the VBA macros.
- 3. Enable the VBA Editor: Navigate to the Developer tab and click 'Visual Basic', or press ALT + F11 to access the built-in VBA editor.
- 4. Run Your Code Error-Free: Apply the corrected MATCH and OFFSET functions and run your macro to process your data without boundary errors.

Frequently Asked Questions
Why does my VBA MATCH function return Error 1004?
Error 1004 typically occurs when the lookup value isn't found, or if you apply an OFFSET to an entire row or column that pushes the reference beyond Excel's maximum grid boundaries. Ensuring the range stays within valid columns and rows prevents this.
How do I extract a specific column from a named range in VBA?
You can use the Columns(index) property on the range object. For instance, Range("MyData").Columns(3) will return the third column of the named range 'MyData', bypassing the need to use the Offset method.
Can I use MATCH for dates in VBA?
Yes, but WorksheetFunction.Match expects dates to be formatted as numerical Excel serial numbers. You must convert your date string to a Long integer using CLng(CDate("YourDate")) before passing it into the Match function.
Is Application.WorksheetFunction.Match the same as Application.Match?
They execute the same logic but handle errors differently. WorksheetFunction.Match halts the code and throws a runtime error if no match is found. Application.Match returns an error variant that you can check using IsError() without breaking the execution flow.




