View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett Don Guillett is offline
external usenet poster
 
Posts: 10,124
Default parsing a string for 3 sets of numbers

try this to get numbers, spaces and periods ( . )

45672 223 12.42


Sub ExtractNumbersFromText()
For Each c In Range("d2:d4")
ms = ""
For i = 1 To Len(c.Value)
x = Mid(c.Value, i, 1)
If x Like "*[0-9]*" _
Or x = " " Or x = "." Then
ms = ms & Mid(c, i, 1)
End If
Next i
MsgBox Application.Trim(ms)
Next c
End Sub

--
Don Guillett
SalesAid Software

"Micah" wrote in message
...
I have a spreadsheet with various words and numbers in each cell. The
arrangement of numbers in the string can vary. I want to extract from the
text string, the first 3 numbers as numbers.

Example

dog a cat 45672 223 12.42 mouse caught

I want to parse the above string (which is in a cell) and get
45672
223
12.42