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
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
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.
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0
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?
 
Upvote 0
I changed the Range variable to an array variable. It seems to be correctly returning the position value in the array as intended.
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,141
Members
453,021
Latest member
Justyna P

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