Run-time error 1004 With Excel Match Function on Cells Containing Dates in VBA

I was attempting to use the Excel worksheet function Match in VBA to find a cell with a particular date.

I had the following line of code (where myDate was a variable of Date type):

requiredRow = Application.WorksheetFunction.Match(myDate, Worksheets("Sheet1").Range("A1:A31"),0)

This line of code was throwing the following (unhelpful) error:

Runtime Error '1004'
 Unable to get the Match property of the WorksheetFunction class

The way to get the match to work is to convert your date to a Long data type.


requiredRow = Application.WorksheetFunction.Match(CLng(myDate), Worksheets("Sheet1").Range("A1:A31"),0)

A very frustrating issue with a very unhelpful error message.

Be First to Comment

Leave a Reply