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
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

On Error GoTo 0
Exit Function

GoTo Exit_For

End Function

No comments: