Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

removing spaces and non-numeric characters 1

Status
Not open for further replies.

sedgely

Technical User
Feb 21, 2002
406
GB
I have a table containing phone numbers, these are entered manually and therefore are in different formats what i need to do is remove all spaces and non-numeric characters, does anyone know a neat way of doing this?

Cheers
Craig
 
Use the SUBSTITUTE() function:

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1," ",""),"-",""),":",""),"*",""),"_",""),"(",""),")","")

This will remove all of the spaces and non-numeric characters in cell A1.

I hope this helps!



Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
Or there is a IsNumeric

So something like

FOR X = 1 to Len(Me.txtPhoneNumber.Value)
IF ISNUMERIC Mid(Me.txtPhoneNumber.Value,X,1) THEN
'Some Code to remove the offending Character
END IF
NEXT

alternativley Use a Input Mask and set it to accept Numbers
 
Hi,

Taking Sylv4n's code one step further...
Code:
sPhone = ""
FOR X = 1 to Len(Me.txtPhoneNumber.Value)
  sByte = Mid(Me.txtPhoneNumber.Value,X,1)
  Select Case sByte
     Case is "0" to "9"
       sPhone = sPhone & sByte
  End Select
NEXT


Skip,
Skip@TheOfficeExperts.com
 
Good solution I must admit I could not think of the logig to remove the character, but moving it to another variable - Genius!
 
or you could add a reference to the Microsoft VBScript Regular Expressions library, and use the following:
[tt]
Private Function CleanPhoneNumber(strSource as String) As String
With New RegExp
.Global = True
.Pattern = "([\D+])"
CleanPhoneNumber = .Replace(strSource, "")
End With
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top