Match Failing

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Can anyone see any problems with this line of code which would contribute to an "Unable to get the match property of the Worksheet Function class" error.

Rich (BB code):
With ws_master
    dRow = Application.WorksheetFunction.Match(n_date, .Columns(1), 0)
End With

n_date = 2020-06-04

In worksheet ws_master (defined publically as worksheet), 2020-06-04 is found in call A172, yet this code is unable to find that match.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
date stored as text? Is the date a string or a date? What happens if you write the formula into a worksheet cell for testing?
 
Upvote 0
Hi Teylyn ... I believe it is stored as a date. If I change the cells in column A of ws_roster to number, the value changes to the correct serial for that date.
At the worksheet level, =match(HG2,A:A) where HG2 = 2020-06-04 returnas a value of 172, which would be correct.
 
Upvote 0
It would appear that n_date isn't a number (isnumeric(n_date) = false). That may be the problem? Will have to find out how to convert the n_date (string?) into a number.
n_date_ser = CDate (n_date) didn't work to convert the string 2020-06-04 to a number.
 
Upvote 0
Also tried this approach where n_date = 2020-06-04 (observations in green). I suspect maybe I was using IsNumeric wrong thinking that date should be a number.

Rich (BB code):
n_date_ser = DateValue(n_date)  '2020-06-4 
n_date_ser = IsNumeric(n_date)  'FALSE
n_date_ser = DateSerial(Left(n_date, 4), Mid(n_date, 6, 2), Right(n_date, 2))  '2020-06-4
n_date_fmt = format(n_date_ser,"00000")  ' "43987"
n_date_num = IsNumeric(n_date_ser) 'FALSE
dRow = Application.WorksheetFunction.Match(n_date_ser, ws_roster.Columns(1), 0) 'Unable to get the Match property ...
 
Last edited:
Upvote 0
How is n_date declared? If it's a string, use:

Code:
Application.WorksheetFunction.Match(CDbl(CDate(n_date)), ws_roster.Columns(1), 0)
 
Upvote 0
Hi Rory, I was working on a post as you were answering. I will give your suggestion a try, but n_date is declared as Date.

Edit: Did not work. Same error.
 
Upvote 0
If n_date is declared as a date, it would just be:

Code:
Application.WorksheetFunction.Match(CDbl(n_date), ws_roster.Columns(1), 0)

If that doesn't work, it's most likely an issue either with your data (eg column A has time parts, or is stored as text) or with how you are populating the date variable.
 
Upvote 0
Thank you Rory. You got me looking through my code more closely and noticed that although I had n_date declared publicly, I also had it locally dimmed in my module as long. I removed it and things improved. Not sure why, but it did.
 
Upvote 0

Forum statistics

Threads
1,215,035
Messages
6,122,791
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top