Is member of an array?
Shatin,
Sub test()
Dim arr(100 - 1) As String, i As Long, strVariable As String, blnFound
As Boolean
For i = 0 To 100 - 1
arr(i) = "Hello " & i & i & i
Next
strVariable = "Hello 565656"
blnFound = False
For i = 0 To 100 - 1
If arr(i) = strVariable Then
blnFound = True
Exit For
End If
Next
If blnFound Then
MsgBox "Search string found in array element " & i
Else
MsgBox "Search string not found"
End If
End Sub
Rob
"Shatin" wrote in message
om...
Let's say I have an array with 100 string elements. Now I have to
check if a particular string is same as one of the elements in the
array, is there a simple way of doing so instead of using many
If/Elseif statements?
If not, I suppose one would have to use some kind of lookup functions.
In that case, does it necessarily mean one would have to include a
data worksheet (invisible or otherwise) in the file for the lookup?
For example, there are 100 string elements in column H. I then create
the newArray by applying various left/mid/right functions to column H.
How do I check if strVariable is same as one of the elements in
newArray? Do I have to list all the elements of newArray on a data
worksheet first?
TIA
|