In all likelihood, no match was found. In this case, Application.Match
returns an Excel error code, that is, a variant / error whose value is Error 2042
(this corresponds to getting #N/A
in Excel).
This error value cannot be forced to bind to String (this is what MsgBox
expects), and thus you get a type mismatch.
Note that with WorksheetFunction.Match
you can call the same Match
function. The only difference is how to handle errors:
With WorksheetFunction
errors are treated as VBA errors that can be used using the On Error
syntax.
Using Application
they return an Excel error code wrapped in a variant. You can use IsError
to see if the returned variable is an error type variant.
source share