Remove non-numerics from a field?

M

mscertified

I need a fast function to remove all non-numeric characters from a field,
what is the best way to do it?
It must remove any embedded spaces, e.g.
AB12 3C must become 123
 
D

Douglas J. Steele

Untested air-code:

Function RemoveNonNumeric(InputString) As String
Dim lngLoop As Long
Dim strCurrChar As String
Dim strOutput As String

For lngLoop = 1 To Len(InputString)
strCurrChar = Mid$(InputString, lngLoop, 1)
If strCurrChar >= "0" And strCurrChar <= "9" Then
strOutput = strOutput & strCurrChar
End If
Next lngLoop

RemoveNonNumeric = strOutput

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top