View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Operator Question

If you want to test whether a string is in a single variable, use
the InStr function:

Dim S As String
Dim Res As Long
S = "code1,code2,code3"
Res = InStr(1, S, "code2")
If Res 0 Then
Debug.Print "found"
Else
Debug.Print "not found"
End If

If you have an array of values, use the Match worksheet function.

Dim A As Variant
Dim N As Variant
A = Array("code1", "code2", "code3")
N = Application.Match("code2", A, 0)
If Not IsError(N) Then
Debug.Print "found"
Else
Debug.Print "not found"
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"kmbarz" wrote in message
...
Just getting back into vba after a couple of year stint in SAS
and Coldfusion
so I'm a bit rusty. Is there something in Excel VBA that works
like an IN
operator in other languages? (e.g. var IN
('code1','code2','code3')) I
don't see anything in the help so far.
Thanks