Thread: InStr question
View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default InStr question

Hi,

Yiu could do this. the message boxes are to illustrate it is working and
wouldn't be necessary in your final code

Sub SplitOut1()
searchstring = "1"
Dim numstring As Variant
numstring = "99,15,21,1"
b = Split(numstring, ",")
For x = 0 To UBound(b)
If b(x) = searchstring Then
found = True
Exit For
End If
Next
If Not found Then
MsgBox searchstring & " Not Found"
Exit Sub
End If
'do things
MsgBox searchstring & " Found"

End Sub

Mike

"CG Rosen" wrote:

Good day group,

Trying to use the InStr function in VBA to find if various numbers is
contained in a string.

If InStr(c.value, "String") 0
Then..........................................etc

The c.value can be from 1 to 50. The string can look like "1,15,21" . If the
c.value =1 that number
is then found 3 times. How is it possible to do a distinction that 1 is only
found one time and 2 one time and say 21 one time and so on? Do I need some
other kind of separator in the string?

Hope my question is understandable.

Brgds

cgr