Custom Search

Friday, November 28, 2008

Is In Array

Public Function IsInArray(ByVal FindValue As Variant, _
ByVal aryToSearch As Variant, _
Optional CaseSensitive As Boolean = True) As Boolean

On Error GoTo Hell

'Make sure array was passed
If Not IsArray(aryToSearch) Then Exit Function

'Determine search type
Dim lngSearchType As Long
If CaseSensitive Then
lngSearchType = vbBinaryCompare
Else
lngSearchType = vbTextCompare
End If

'Create a string of the array and attempt to
'locate the Value
IsInArray = InStr(1, vbNullChar & Join(aryToSearch, _
vbNullChar) & vbNullChar, vbNullChar & FindValue & _
vbNullChar, lngSearchType) > 0

Exit_For:
On Error GoTo 0
Exit Function

Hell:
GoTo Exit_For

End Function

No comments: