Hello.
I have a list of contacts that I am trying to "clean-up" the data.
A column of phone numbers have been entered in a variety of different ways
(e.g. 555.555.5555; (555) 555-5555; Home: 555-5555; etc.)
How can I remove the non-numeric characters?
Thanks in advance!
Several ways:
Assuming your data is in A1.
==================================
From Harlan Grove:
First, create a Named Formula
Names in Workbook: Seq
Refers to: =ROW(INDEX($1:$65536,1,1):INDEX($1:$65536,255,1))
This ARRAY FORMULA
(committed with CTRL+SHIFT+ENTER, instead of just ENTER)
removes ALL non-numerics from a string.
In sections, for readability:
B1: =SUM(IF(ISNUMBER(1/(MID(A1,seq,1)+1)),MID(A1,seq,1)*
10^MMULT(-(seq<TRANSPOSE(seq)),-ISNUMBER(1/(MID(A1,seq,1)+1)))))
================================
Or you can use a UDF:
To enter this User Defined Function (UDF), <alt-F11> opens the Visual Basic
Editor.
Ensure your project is highlighted in the Project Explorer window.
Then, from the top menu, select Insert/Module and
paste the code below into the window that opens.
To use this User Defined Function (UDF), enter a formula like
=DigitsOnly(A1)
in some cell.
=================================
Option Explicit
Function DigitsOnly(str As String) As Double
Dim re As Object
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = "\D+"
DigitsOnly = re.Replace(str, "")
End Function
=============================
--ron