G
Greg
Hello,
I have a macro that I now use for stipping out non-numerical characters
from a string (Thanks Andi Mayer). This works great, but I was
wondering if there is a function available that might simplify the
process so that it doesn't have to cycle through each charcter? I
found VAL(myStr), but this only pulls out the leading numeric
characters. Is there something else that I should be using?
Thanks.
Sub StripOutNonNumerics()
Dim oChrNum As Long
Dim i As Long
Dim myStr As String
Dim tmpStr As String
myString = Selection.Range.Text
For i = 1 To Len(myStr)
oChrNum = Asc(Mid(myStr, i, 1))
If oChrNum >= 48 And oChrNum <= 57 Then
tmpStr = tmpStr + Chr(oChrNum)
End If
Next i
myStr = tmpStr
Selection.Range.Text = myStr
End Sub
I have a macro that I now use for stipping out non-numerical characters
from a string (Thanks Andi Mayer). This works great, but I was
wondering if there is a function available that might simplify the
process so that it doesn't have to cycle through each charcter? I
found VAL(myStr), but this only pulls out the leading numeric
characters. Is there something else that I should be using?
Thanks.
Sub StripOutNonNumerics()
Dim oChrNum As Long
Dim i As Long
Dim myStr As String
Dim tmpStr As String
myString = Selection.Range.Text
For i = 1 To Len(myStr)
oChrNum = Asc(Mid(myStr, i, 1))
If oChrNum >= 48 And oChrNum <= 57 Then
tmpStr = tmpStr + Chr(oChrNum)
End If
Next i
myStr = tmpStr
Selection.Range.Text = myStr
End Sub