View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
diana
 
Posts: n/a
Default Function to extract numbers from an alphanumeric cell

I was off for the week-end. Hope you check in to find out if I have answered
Niek.
Your UDF works like Magic. Many thanks.

"Niek Otten" wrote:

You could use this UDF. It returns a string, so you would use it as

=Value(StripTxt(A1))

If you're new to VBA, read this first:

http://www.mvps.org/dmcritchie/excel/getstarted.htm


The Function:

Function StripTxt(a As String) As String
' Strips all non-numeric characters from a string
' Returns a string, not a number!
Dim i As Long
Dim b As String
For i = 1 To Len(a)
b = Mid$(a, i, 1)
If ((Asc(b) 47 And Asc(b) < 58) Or b = Application.DecimalSeparator) Then StripTxt = StripTxt + b
Next i
End Function


--
Kind regards,

Niek Otten

"diana" wrote in message ...
Is there a function that will read the numbers only of an alphanumeric cell:
Cell that contains a word and number.
Appreciate anybody's help in this respect.