![]() |
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 |
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 |
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 |
All times are GMT +1. The time now is 09:57 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com