Hi, Is there a way in Excel VBA to do somthing like :- If myVariable In ["eggs", "ham", "potato"] or do you have to have lots of "OR" statements Thanks Phil
Hi, Is there a way in Excel VBA to do somthing like :- If myVariable In ["eggs", "ham", "potato"] or do you have to have lots of "OR" statements Thanks Phil
[vba]
Dim myArray As Variant
Dim myVariable As String
Dim aryIdx As Long
myArray = Array("eggs", "ham", "potato")
myVariable = "eggs"
On Error Resume Next
aryIdx = Application.Match(myVariable, myArray, 0)
On Error GoTo 0
If aryIdx > 0 Then
MsgBox "Found in item " & aryIdx
End If
[/vba]
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
Another approach might be
[VBA]Select Case myVariable
Case "pear", "apple", "peach"
MsgBox "vegetable"
Case "steak", "bacon", "sausage"
MsgBox "meat"
End Select[/VBA]xld's method is better if you only want "is it in the bucket, True/False". Select Case would be used if the question is "which bucket is it in"?