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.

This entry was posted in Programming and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s