View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ken Johnson Ken Johnson is offline
external usenet poster
 
Posts: 1,073
Default Extract Numbers From String


BerkshireGuy wrote:
I have a field formatted like the following:

2340/LEFT EYE BLINDNESS, 2341/CAP PRES-
2340/LEFT EYE BLINDNESS, 2341/CAP PRES-
2340/LEFT EYE BLINDNESS, 2341/CAP PRES-
2112/M&N
2112 MENTAL/NERVOUS, 2801 ASTHMA_______
2112 MENTAL/NERVOUS, 2801 ASTHMA_______
2112 MENTAL/NERVOUS, 2801 ASTHMA_______
2112 MENTAL/NERVOUS, 2801 ASTHMA_______
REIS:ADD 2960/THORACIC, 2918/EITHER OR
REIS:ADD 2960/THORACIC, 2918/EITHER OR
REIS:ADD 2960/THORACIC, 2918/EITHER OR
REIS:ADD 2960/THORACIC, 2918/EITHER OR

Is there a way to extact just the numbers and if there is more than one
number, seperate it by a comma? Note: Each of the numbers are 4 digits
in length.

ex - first row should read 2340, 2341

TIA!


Hi,

Try this user defined function (requires XL2000 or higher)...

Public Function Numbers(Cell As String) As String
Cell = WorksheetFunction.Substitute(Cell, "/", " ")
Dim StrArray As Variant, I As Long
StrArray = Split(Cell)
For I = 0 To UBound(StrArray)
If IsNumeric(StrArray(I)) Then
Numbers = Numbers & StrArray(I) & ", "
End If
Next I
If Len(Numbers) 2 Then
Numbers = Left(Numbers, Len(Numbers) - 2)
End If
End Function

Ken Johnson