unable to get the match property of the worksheet function class

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
I am receiving the error "unable to get the match property of the worksheet function class". I suspect my data as input into the function is not allowing for the smooth operation of the function. Below is the code.

Code:
C = TS.Cells(A, "A").value    D = TS.Cells(A, "B").value
    E = TS.Cells(A, "C").value 
    
    Set G = PBK.Range("A1").CurrentRegion
    
    F = Application.WorksheetFunction.Match(D, G, 0)

TS is a workbook.worksheet variable

D is a Date variable

G is a Range variable
 

Some videos you may like

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,916
It sounds like D is not in the range G.

Try something like
Code:
Dim F as Variant

' ...
F = Application.Match(D, G, 0)

If IsError(F) Then
    MsgBox "D not there"
Else
    MsgBox "D is there"
End If
Application.Match will return an error value, Application.WorksheetFunction.Match will cause a VBA error.
 

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
still having trouble...I changed the D and G variables to variants and rewrote G to

Code:
Set G = PBK.Range(Cells(1, "A"), Cells(N, "I"))

D is present in the first column of the array G. What other methods can I use to troubleshoot this error? I am watching the related variables. G has a "count" value (under add watch) that is probably correct given the number of columns and rows. The other variables are giving values too.
 

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,916
Match works on a single column or row of cells, your G has more than than.
 

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614

ADVERTISEMENT

changed G to read

Code:
Set G = PBK.Range(Cells(1, "A"), Cells(N, "A"))

even with the single column in the range the match is giving the same error
 

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
the match line

Code:
F = Application.Match(D, G, 0)

includes D as a Variant, G as a Range, and F as a Variant. G is a single column (column "A").

when I run it currently the D variable is established correctly as a date "9/5/2007", but the F variable element in Add Watch window reads Error 2042. I've looked through the range and have not observed any cells with the contents "N/A#" in them. Any ideas why as to how this error is being generated?
 

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
I changed the Range variable to an array variable. It seems to be correctly returning the position value in the array as intended.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,950
Messages
5,599,028
Members
414,275
Latest member
Pungie

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
Top