Format phone numbers to look the same

A

Access Joe

Hey everyone!

I have an XL spreadsheet with tens of thousands of phone numbers, all
entered in different ways. IE

COLUMN A - PHONE NUMBER
973-555-1234
(973) 454-1291
none
(456) 555-3241
283 228 0293
home-(973) 555-1223

See - people entered data all different ways. I can't control the data
entry. But what I need to do is find a way to reformat the results so all
the numbers look like this: (###) ###-####

Can anyone help? Thanks so much!
 
A

Access Joe

Thanks a lot. This worked!

edvwvw via OfficeKB.com said:
The following VBA (credit to the original poster) creates a User defined
Function

Alt F11 insert Module and paste the folowing code

Public Function GetNumbers(sText As String)

With CreateObject("vbscript.regexp")
.Pattern = "\D"
.Global = True
GetNumbers = .Replace(sText, "")
End With
End Function

The usage is as follows - assume that the data is in column A in B put the
following formula

=getnumbers(A1)*1 ( The *1 changes it from text to nembers so you can now
apply the custom format that you want)

edvwvw
 

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