Excel VBA函数未找到数组中的完全匹配

时间:2017-10-01 20:12:34

标签: arrays excel vba excel-vba

我有一个包含“Hot Soup”的数组。当我在If语句中使用以下函数来测试是否在数组中找到“Soup”时,它返回true:

Function FindInArray(StringToBeFound As Variant, ThisArray As Variant) As Boolean

  FindInArray = (UBound(Filter(ThisArray, StringToBeFound)) > -1)

End Function

测试:

Sub Test()

    Dim bool As Boolean

    myArray = Array("Hot Soup", "Vanilla")
    bool = FindInArray("Soup", myArray)
    MsgBox bool

End Sub

返回true,但不是。如果匹配准确,是否有办法返回true?

谢谢!

0 个答案:

没有答案