Excel VBA: Can't get a match, error "Unable to get the Match property of the WorksheetFunction class"

Humble Val

For the love of all that is good, I cannot seem to get this to work. I keep getting the error mentioned above.

I have this table, and I'm trying to find out whether the code matches it's own sub-code somewhere within the other column, however it's erroring out. Your help is greatly appreciated.

enter image description here

Sub testing()

    Dim m1 As long
    Dim myrange As Range

    Set myrange = Worksheets("Sheet1").Range("B2:B23")

    For e = 2 To 23
        m1= Application.WorksheetFunction.Match(Cells(e, 1).Value, myrange, 0)

        If m1 > 0 Then
            Cells(e, 3).Value = "Yes"
        Else
            Cells(e, 3).Value = "No"
        End If
    Next e

MsgBox "Complete!"

End Sub
David Zemens

Use the Application.Match function which allows for better ability to trap errors. When using the WorksheetFunction.Match, when a match is not found, it returns an error, which is what you're experiencing.

If Not IsError(Application.Match(Cells(e, 1).Value, myrange, 0)) Then
    'Do stuff when the match is found
    Cells(e, 3).Value = "Yes"
Else:
    Cells(e, 3).Value = "No"
End If

You could also potentially use the CountIf function:

If Application.WorksheetFunction.CountIf(myRange, Cells(e,1).Value) > 0 Then
    Cells(e,3).Value = "Yes"
Else:
    Cells(e,3).Value = "No"
End If

Neither of these approaches requires you to use the m1 variable, you can assign this variable within the True part of the If/Then statement, if you need to identify where the match is found.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Unable to get Match property of the WorksheetFunction class

From Dev

Match function error excel vba

From Dev

Excel VBA - index and match vba error

From Dev

Excel VBA Error Handling (simple but i can't figure it out)

From Dev

Can't Get Excel to Print a Specific Worksheet Using VBA

From Dev

Can't get excel vba function with two arguments to work

From Dev

Excel, VBA, can't get cell from row and column ID

From Dev

VBA error handling (INDEX/MATCH in Excel)

From Dev

Excel VBA - Match Function gives error in loop

From Dev

Match Not working Excel: Error 1004 Unable to get the Match Property

From Dev

VBA - (Excel) Why can't I set Textbox type for Userform without getting a type mismatch error?

From Dev

Excel VBA run-time error 1004 which I can't identify

From Dev

Can´t add = in formula with VBA, Excel

From Dev

Can't override Excel shortcuts via VBA

From Dev

Can't access Excel VBA Code

From Dev

I can't get my VBA Excel Macro to stop at the end of the row

From Dev

WorksheetFunction.Match multiple sheets Excel VBA error 1004

From Dev

Excel VBA: how to solve Index and Match function type mismatch error

From Dev

Can't get MATCH AGAINST to work with wildcard

From Dev

Can't get java to match regex with matches()

From Dev

LWJGL Can't get coordinates to match up

From Dev

sed can't get string match

From Dev

Can't get MATCH AGAINST to work with wildcard

From Dev

Can't get java to match regex with matches()

From Dev

Can't get jest snapshot match to pass

From Dev

VBA Error Handling: Unable to get the match property of the worksheet function class

From Dev

Why do I get Error 2042 in VBA Evaluate INDEX/MATCH?

From Dev

VBA can't get array to resize

From Dev

Excel VBA: Match Cell Color

Related Related

  1. 1

    Unable to get Match property of the WorksheetFunction class

  2. 2

    Match function error excel vba

  3. 3

    Excel VBA - index and match vba error

  4. 4

    Excel VBA Error Handling (simple but i can't figure it out)

  5. 5

    Can't Get Excel to Print a Specific Worksheet Using VBA

  6. 6

    Can't get excel vba function with two arguments to work

  7. 7

    Excel, VBA, can't get cell from row and column ID

  8. 8

    VBA error handling (INDEX/MATCH in Excel)

  9. 9

    Excel VBA - Match Function gives error in loop

  10. 10

    Match Not working Excel: Error 1004 Unable to get the Match Property

  11. 11

    VBA - (Excel) Why can't I set Textbox type for Userform without getting a type mismatch error?

  12. 12

    Excel VBA run-time error 1004 which I can't identify

  13. 13

    Can´t add = in formula with VBA, Excel

  14. 14

    Can't override Excel shortcuts via VBA

  15. 15

    Can't access Excel VBA Code

  16. 16

    I can't get my VBA Excel Macro to stop at the end of the row

  17. 17

    WorksheetFunction.Match multiple sheets Excel VBA error 1004

  18. 18

    Excel VBA: how to solve Index and Match function type mismatch error

  19. 19

    Can't get MATCH AGAINST to work with wildcard

  20. 20

    Can't get java to match regex with matches()

  21. 21

    LWJGL Can't get coordinates to match up

  22. 22

    sed can't get string match

  23. 23

    Can't get MATCH AGAINST to work with wildcard

  24. 24

    Can't get java to match regex with matches()

  25. 25

    Can't get jest snapshot match to pass

  26. 26

    VBA Error Handling: Unable to get the match property of the worksheet function class

  27. 27

    Why do I get Error 2042 in VBA Evaluate INDEX/MATCH?

  28. 28

    VBA can't get array to resize

  29. 29

    Excel VBA: Match Cell Color

HotTag

Archive