View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
wcc wcc is offline
external usenet poster
 
Posts: 3
Default does an item belong to an array?

Thanks to Norman, keepITcool & Dana.

- wcc

"Dana DeLouis" wrote in message ...
If you would like to check all months against either the short and long
month name, here's a similar idea.

Sub Valid_Month()
Dim v1, v2
Dim Chk As Long
Dim sRes As String
Const msg1 As String = _
"Type month (3 letters,or full month): "

With Application
v1 = .GetCustomListContents(3)
v2 = .GetCustomListContents(4)
End With

sRes = InputBox(msg1)
If sRes = vbNullString Then Exit Sub

On Error Resume Next
With WorksheetFunction
Chk = 0 'False
Chk = .Match(sRes, v1, 0)
Chk = Chk + .Match(sRes, v2, 0)
End With

If Chk Then
MsgBox "Valid"
Else
MsgBox "Not Valid", vbExclamation
End If

End Sub

HTH
--
Dana DeLouis
Win XP & Office 2003


"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