View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_1866_] Rick Rothstein \(MVP - VB\)[_1866_] is offline
external usenet poster
 
Posts: 1
Default Instr syntax help

You have the arguments backwards. You would want...

If InStr("51693 61121 52401 61151 61191 52231 ", Proj) Then

However, in order to guarantee you don't get a false match (for example,
when an accidental value of, say, 169 is assigned to Proj), it is better to
add your delimiter (the space character in this case) to both ends of the
text to be searched **and** the search string itself (this effectively turns
the InStr search into a "word only" type mode). So, I would rewrite the
above line like this...

If InStr(" 51693 61121 52401 61151 61191 52231 ", " " & Proj & " ") Then

Note that the list of values I used above is missing the last number from
the list you provided. I did that so the statement would not word-wrap in
some newsreaders. However, the concept is the same no matter how long the
text list is... a delimiter on both sides of the delimited list.

Rick



"u473" wrote in message
...
I cannot find in all my doc the proper syntax for Instr to replace my
long
If Proj = "51693" Or Proj = "61121" Or Proj = "52401" Or ..... Then
with something like
If Instr(Proj,"51693 61121 52401 61151 61191 52231 52401") Then
But what is the proper syntax with quotes, spaces & commas ?

...............
Range("A1").Select
Do
Proj = ActiveCell.Value
' Test the ActiveCell.Value against 10 allowed values
If Proj = "51693" Or Proj = "61121" Or Proj = "52401" Then
' Do something
End If
ActiveCell.Offset(1, 0).Select
Loop Until ActiveCell.Row LastRow
Thank you for your help
Celeste