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

后端 未结 3 1665
遇见更好的自我
遇见更好的自我 2021-01-23 00:10
Sub Sales_Summary_Macro()

    Dim strMake, strModel, strCount As String
    Dim makeLoc, modelLoc, countLoc As Integer

    strMake = Application.InputBox(\"Make\")
            


        
3条回答
  •  甜味超标
    2021-01-23 00:35

    Not going full technical and will not post code. However, three things:

    One, make sure your ranges are always fully qualified. For example, Range("A1:A10") is not nearly enough. You should specify on which sheet this should be located. If you are calling this macro from another sheet, it will give you a wrong result or throw an error.

    Two, without going to too much details:

    1. Application.Match returns an error value if there's no match found. This can be handled using IsError, which is what simoco did in his answer.
    2. WorksheetFunction.Match throws a 1004 error when it doesn't find an error. This is not the same as returning a value. As such, this is (slightly) harder to handle.

    Best practice is to always use the first one.

    Three, the immediate window in VBE is your best friend. A simple ?Application.Match("FindMe", [A1:A10], 0) in the window can help you check if your formula is netting a similarly intended result.

    Application.Match returning an error value

    As shown in the screenshot above, no string is found and an error value is returned.

    Hope this helps!

提交回复
热议问题