View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
R. Choate R. Choate is offline
external usenet poster
 
Posts: 106
Default Extract 10 digit number from string

Well, I'm getting the understanding that so far, people feel that I'm just going to have to loop through every string while I loop
through every row (thousands of rows). I would really love to avoid looping through every character until I find 10 digits if that
is possible. I can't believe there isn't a built-in method for this. That is going to put a real time eater in my app.

If anybody can think of a way to do this without going through each string, character by character, please tell me. For those who
have given me code which does loop through, I thank you for your time and your help.
--
RMC,CPA


"Toppers" wrote in message ...
Hi,

See if this helps:


Sub Test()
Call FindTenDigits("1abc1234defghi1234567890zt1")
End Sub


Sub FindTenDigits(FindStr)

For i = 1 To Len(FindStr)

If IsNumeric(Mid(FindStr, i, 1)) Then
For j = i To Len(FindStr)
If Not IsNumeric(Mid(FindStr, j, 1)) Then
If j - i = 10 Then
NumStr = Mid(FindStr, i, 10)
MsgBox NumStr & " found in string " & FindStr
Exit Sub
End If
i = j
Exit For
End If
Next j
End If

Next i

End Sub


"R. Choate" wrote:

They are all over the place. A stupid data entry person enters everything randomly. The numbers could be anywhere in the string,
otherwise I would just look for the delimiter. That would be easy. The only constant is that it is always 10 digits...somewhere in
the string.
--
RMC,CPA


"Toppers" wrote in message ...
Richard,
How are the (numeric) strings delimited e.g. 1234,abc,123456?

"R. Choate" wrote:

I need to find and extract a 10 digit number from a string which might contain more than one numeric string, but there would
only
be
one string of that length. I'm going to have to find out how to do this and then loop through a long list and extract that
number
and place it in the first cell to the right (column B). I've been at this all morning. I'm out of ideas. Surely there is an easy
way
to do this that I'm just not thinking of. Help !

Thanks in advance !

Richard
--
RMC,CPA