Find if a value exists in an Array
No attachments for this post
This handy little function will determine if a value is present in an array, and return true or false.
Public Function IsInArray(FindValue As Variant, arrSearch As Variant) As Boolean
On Error GoTo LocalError
If Not IsArray(arrSearch) Then Exit Function
If Not IsNumeric(FindValue) Then FindValue = UCase(FindValue)
IsInArray = InStr(1, vbNullChar & Join(arrSearch, vbNullChar) & vbNullChar, _
vbNullChar & FindValue & vbNullChar) > 0
'Justin (just in case)
Private Sub Command1_Click()
Dim x(5) As String
x(0) = 5
x(1) = 100
x(2) = 2000
x(3) = 11
x(4) = 7
x(5) = 1010
MsgBox IsInArray(10, x)
This code originally appeared on AndreaVB.com, and has been republished here with the permission of Andrea Tincani.
Comments on this post
No comments have been added for this post.
You must be logged in to make a comment.