Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Operator Question
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Operator Question
One way to do this is use Select Case
Select Case x Case "code1","code2","code3" ........ case "code4" ..... End select Is this what you were looking for? Alok "kmbarz" wrote: 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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
IF formula-simple question; simple operator | Excel Discussion (Misc queries) | |||
Operator Question | Excel Discussion (Misc queries) | |||
Operator | Excel Worksheet Functions | |||
what does ~ operator mean? | Excel Discussion (Misc queries) | |||
Just a question regarding a formula operator. | Excel Programming |