Phone number insanity

Dragonflight

New Member
Joined
Nov 26, 2002
Messages
11
I'm working on a thousand-line database, and we need to streamline the data to a uniform format. The data was provided from all over the place, so the phone number data is formatted in just about every way there is. For example:

(123) 456-7890 <--- this is the desired result
1-234-567-8900
123-4567
123-456-7890
123- 456-7890
123 456 7890

The thought of having to go through this list manually horrifies me. It's got two phone numbers, cell, pager, fax, and alternate contact numbers, all done up in this jumble. Manual formatting would drive me insane. Is there a way to fix this problem faster?
 
Added a little error trap:

Sub ConvertPhoneNumbers()
'Sheet module code, like: Sheet1.
Dim c As Range
Dim myLen, myBad$

With Range([A1], [A65536].End(xlUp))
.Replace What:="-", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
.Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
.Replace What:="(", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
.Replace What:=")", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
End With

For Each c In Range([A1], [A65536].End(xlUp))
myLen = Len(c)
If myLen = 11 Then
c = Right(c, 10)
myLen = 10
End If
If myLen = 10 Then
c.NumberFormat = "(###) ###-####"
End If
If myLen = 7 Then
c.NumberFormat = "###-####"
End If
If myLen > 13 Or myLen = 12 Or myLen = 9 Or myLen = 8 Or myLen < 7 Then
myBadNum = c.Value & " Bad#?"
c.Value = myBadNum
End If

Next c
End Sub
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,225,481
Messages
6,185,236
Members
453,283
Latest member
Shortm88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top