Trying to use application.match function with 2 match criteria in VBA to return a row number where both criteria exist. I can type directly into my worksheet and get the correct answer, but when converting to VBA code I receive a type mismatch error (13)
.
This is what I type into the worksheet directly and get the correct row number returned: {=Match(1,("Criteria 1" = A:A)*("Criteria 2" = B:B),0)}
. Criteria 1 and Criteria 2 are text strings. Data within column A and column B are a mixture of text and numbers.
This is the equivalent code I tried in VBA which resulted in Type mismatch error:
Result = application.match(1,(Criteria 1 = Range("A:A"))*(Criteria 2 = Range("B:B")), 0)
Tried a shorter test line, and also got type mismatch error:
Test = Application.match(1,(Criteria 1 = Range("A:A"),0)
I expected this code to return the row number (Result) where both Criteria 1 and Criteria 2 existed. The Locals window shows that Criteria 1 is a Variant/String. I tried a cut down version of the code, and got similar error. The result in this case was Test, and the Locals window showed that Test type was Variant/Double, Criteria1 was Variant/String and Range("A:A") is Variant/Variant (I assigned Range(A:A) to a variable to determine this)