
search number in a text string
Daniel,
Let me add a little to the response Jan gave. When I read your post it
sounds like you want to find any and all numbers in a text string, not
just a single digit. As an example, assume your text string is:
12FS+3d. The following code will find the location of all three digits
in the string and put the locations into an array for use elsewhere in
your code.
Sub FindNumInString()
Dim DigLocation() As Integer
str1 = "12FS+3d"
Redim DigLocation(Len(str1))
i = 1
p = 1
While p <= Len(str1) And p > 0
For dig = 0 To 9
If InStr(1, str1, CStr(dig)) > 0 Then
p = InStr(1, str1, CStr(dig))
DigLocation(i) = p
i = i + 1
str1 = Mid(str1, p + 1)
Exit For
Else
p = 0
End If
Next
Wend
a = DigLocation(1) 'value = 1
b = DigLocation(2) 'value = 2
c = DigLocation(3) 'value = 6
End Sub
Hope this helps,
John