View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Retrieve number from string

Function GetNum(Target As Range)

InputData = Target.Value
GetNum = ""
Do While InputData < ""
If Left(InputData, 1) = "0" And _
Left(InputData, 1) <= "9" Then

GetNum = GetNum & Left(InputData, 1)
End If

InputData = Mid(InputData, 2)

Loop

End Function


"Jan Kronsell" wrote:

Hi

I'm gtrying to retrieve a number from a string. The string is a cell value,
that can be

AAAAAA 12 AAA
AA12
12AA
1A2AAA12
AAAA 12 AAAA

or any other combination of letters and numbers. I need at function, that
rerieves only the numbers. The results of above should be

12
12
12
1212
12

Regards
Jan