Application.Match vs Find

我想写一个macros,它将得到列A中的最后一项,并检查它是否存在于列B到D中的任何位置。但是,以下代码永远不会find匹配项并返回“不存在”:

Sub MatchInRange() Dim LastItem As Range Set LastItem = Range("A1").End(xlDown) If Not IsError(Application.Match(LastItem, "B:D", 0)) Then MsgBox "Exists in range" Else MsgBox "Doesn't exist" End If End Sub 

但它使用查找重写时有效:

 Sub FindInRange() Dim LastItem As Range Set LastItem = Range("A1").End(xlDown) If Not Range("B:D").Find(LastItem) Is Nothing Then MsgBox "Exists in range" Else MsgBox "Doesn't exist" End If End Sub 

任何人都可以告诉我,我做错了第一个代码?

匹配适用于1行或列。 您正在使用3 – BCD。 重写这样的第一个公式:

 Sub TestMe() Debug.Print WorksheetFunction.match("TestValue", Range("B:B"), 0) End Sub