Hi all, I am looking to use the 'Find' vba function to test if an element exist in a range array but I am getting a 'Type mismatch error'.
When I swap my array from a range to a list, it works.
Please help.
When I swap my array from a range to a list, it works.
Please help.
VBA Code:
Sub FindBob()
'Create Array
Dim a As String
Dim strName As Variant
strName = Range("A1:A5") 'is generates a Type mismatch error - the range contains the same elements as the list below
'strName = Array("Bob Smith", "John Davies", "Fred Jones", "Steve Jenkins", "Bob Williams") - this method works
'declare a variant to store the filter data in
Dim strSubNames As Variant
'filter the original array
strSubNames = Filter(strName, "Bob")
'if you UBound value is greater than -1, then the value has been found
If UBound(strSubNames, 1) > -1 Then MsgBox ("I found Bob")
End Sub