View Single Post
  #10   Report Post  
Harlan Grove
 
Posts: n/a
Default

"Bob Phillips" wrote...
Easiest way is probably a UDF

Function BreakString(rng As Range, Optional text As Boolean = True)
Dim i As Long
Dim sTemp As String

For i = 1 To Len(rng.Value)
If IsNumeric(Mid(rng.Value, i, 1)) Then
If text Then
'do nothing
Else
sTemp = sTemp & Mid(rng.Value, i, 1)
End If
Else
If text Then
sTemp = sTemp & Mid(rng.Value, i, 1)
End If
End If
Next i
If text Then
BreakString = sTemp
Else
BreakString = Val(sTemp)
End If

End Function

....

The logic could be simplified, no reason to call Mid several times, and
IsNumeric is slower than Like.


Function foo(s As String, Optional n As Boolean) As String
Dim i As Long, k As Long, c As String * 1

k = Len(s)

For i = 1 To k
c = Mid(s, i, 1)
If (c Like "#") = n Then foo = foo & c
Next i

End Function


That said, regular expressions would make this child's play. Using the Subst
udf from

http://groups-beta.google.com/group/...e?dmode=source

(or http://makeashorterlink.com/?S512525CA ), the decimal digits would be
given by

=subst(x,"\D+","")

and the other characters by

=subst(x,"\d+","")