View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default Extracting Digits From Text

Hi,

Try it like this

Function nfw(rng As Range)
Dim RSLT As String
RSLT = ""
For X = 1 To Len(rng.Value)
If Asc(Mid(rng.Value, X, 1)) 47 _
And Asc(Mid(rng.Value, X, 1)) < 58 Then
RSLT = RSLT & Mid(rng.Value, X, 1)
End If
Next
nfw = RSLT
End Function

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Faraz A. Qureshi" wrote:

What could be wrong with the following piece of code for a UDF?

Function NFW(RNG As Range)
Dim RSLT As String
RSLT = ""
For X = 1 To Len(RNG)
If Asc(Mid(RNG.Text, X, 1).Value) 47 And _
Asc(Mid(RNG.Text, X, 1).Value) < 58 Then
RSLT = RSLT & Mid(RNG.Text, X, 1)
End If
Next
NFW = RSLT
End Function

--
Thanx in advance,
Best Regards,

Faraz