does an item belong to an array?
Hi WCC,
You could use the worksheet match function:
Sub Tester01()
Dim sStr As String
Dim arrStr(0 To 2) As String
Dim res As Variant
arrStr(0) = "Jan"
arrStr(1) = "Feb"
arrStr(2) = "Mar"
sStr = InputBox("Type month: ")
On Error Resume Next
res = Application.Match(sStr, arrStr, 0)
If Not IsError(res) Then
'Take appropriate action
MsgBox "Found!"
Else
'Take appropriate alternative action
MsgBox "Invalid value"
End If
On Error GoTo 0
End Sub
---
Regards,
Norman
"wcc" wrote in message
om...
Hello group,
Beginner here. Is there a function to check if an item belongs to an
array?
For exmaple
dim arrStr(0 to 2) as string
dim str as string
arrStr(0) = "Jan"
arrStr(1) = "Feb"
arrStr(2) = "Mar"
str = InputBox("Type month: ")
How do I know if str is a member of arrStr? Do I have to loop through the
array?
Thanks for your attention.
- wccppp
|