VBA & Macro Problems

How to Fix MATCH and OFFSET Formula Errors in Excel VBA

Amos GikundaAmos Gikunda Nov 3, 2026 870 views

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.

How to Fix MATCH and OFFSET Formula Errors in Excel VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

Press ALT + F11 in your spreadsheet to open the Visual Basic for Applications window, then locate the module containing your MATCH or OFFSET code.

2
Locate the full-row 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).

3
Replace Offset with Columns property

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

Specify a Column Property Instead of Offsetting a Full Row
Boundary Preserved: By using the Columns property, you explicitly point to the data you need without shifting the entire row out of the worksheet's allowed dimensions.

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. 1. Download and Install WPS Office: Get the free WPS Office suite from the official website and complete the quick installation process.
  2. 2. Open Your Macro-enabled Workbook: Launch WPS Spreadsheet and open your existing Excel file containing the VBA macros.
  3. 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. 4. Run Your Code Error-Free: Apply the corrected MATCH and OFFSET functions and run your macro to process your data without boundary errors.
Fully compatible with Microsoft Excel VBA syntax and objectsSupports advanced worksheet functions, dynamic arrays, and named rangesLightweight application that runs macros faster and smootherSeamlessly open, edit, and save .xlsm and .xlsb formats
microsoft office alternative - wps office

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.