Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Converting Phone Numbers.

Converting Phone Numbers

by Allen Wyatt
(last updated March 24, 2017)

We have all seen the ads on TV: "Call 1-800-GET THIS for your set of super-sharp knives." You may be faced with the need to convert phone numbers from the text version (as shown on the ads) to the numbers represented by that text. The following macro, DoPhone, will perform the conversion magic for you:

Sub DoPhone()
    Dim rngSrc As Range
    Dim lMax As Long, lCtr As Long
    Dim J As Integer
    Dim Phone As String, Digit As String

    Set rngSrc = ActiveSheet.Range(ActiveWindow.Selection.Address)
    lMax = rngSrc.Cells.Count

    For lCtr = 1 To lMax
        If Not rngSrc.Cells(lCtr).HasFormula Then
            Phone = rngSrc.Cells(lCtr).Value
            For J = 1 To Len(Phone)
                Digit = Ucase(Mid(Phone, J, 1))
                Select Case Digit
                    Case "A" To "P"
                        Digit = Chr((Asc(Digit) + 1) \ 3 + 28)
                    Case "Q"
                        Digit = "7"     'May want to change
                    Case "R" To "Y"
                        Digit = Chr(Asc(Digit) \ 3 + 28)
                    Case "Z"
                        Digit = "9"     'May want to change
                End Select
                Mid(Phone, J, 1) = Digit
            Next J
            rngSrc.Cells(lCtr).Value = Phone
        End If
    Next lCtr
End Sub

The DoPhone procedure tries to convert the information in any cell that does not contain a formula. All you need to do is select the cell (or cells) you want to convert, and then run the procedure. The result is that any text in the cells are converted to their digit equivalents on a phone. Thus, 598-Tips becomes 598-8477.

You should note one small peculiarity of DoPhone, and you may want to change it. Some phones recognize the letters Q and Z as the digits 7 and 9, respectively. Others simply leave these digits out, or they are converted to 0. DoPhone, as written here, converts these letters to 7 and 9. You can change the appropriate places in the Select Case structure, as desired, so they are changed to numbers according to your needs. (The appropriate places are commented in the listing.)

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2269) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Converting Phone Numbers.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Inserting Page Number Cross-References

Want to insert a dynamic cross-reference to a particular page number? It's easy to do following the steps in this tip.

Discover More

Easily Finding Superscripts

Word has a powerful Find and Replace capability, but sometimes it can be tricky to figure out exactly how to use it. Here are ...

Discover More

AutoCorrecting from the Context Menu

Microsoft made what no-doubt appeared to be a small interface change to the Context menus in Word 2013. Problem is, the ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

MORE EXCELTIPS (MENU)

Converting UNIX Date/Time Stamps

If you import information generated on a UNIX system, you may need to figure out how to change the date/time stamps to ...

Discover More

Automatically Converting to GMT

You know what time it is, right? (Quick—look at your watch.) What if you want to know what time it is in Greenwich, ...

Discover More

Converting to ASCII Text

When you work with imported or pasted data in an Excel worksheet, you may see some strange looking characters at times. If ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments for this tip:

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 9 - 7?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.

Links and Sharing