Results 1 to 2 of 2
  1. #1
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    551
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Add parens to first 3 numbers of phone number

    Hello - I have an excel file with a column of phone numbers. They are formatted 000-000-0000. I need them to have parens around the area code (000) 000-0000. I haven't found a way to do this by using a special formatting so I think I need to write a macro to iterate through the cells one by one. There are 900 rows, the phone numbers are in column J. Can anyone help me with this macro? Thank you for the assistance.
    Last edited by RetiredGeek; 2014-01-09 at 10:50.

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    6,176
    Thanks
    200
    Thanked 781 Times in 715 Posts
    JHA,

    You can do this with formatting but you have to eliminate the dashes first.

    Place this code in a module.
    Code:
    Option Explicit
    
    Sub RemoveDashes()
    
    'Note: Place Excel cursor in the column containing the
    '      phone numbers before calling.
     
       Dim lLastRow  As Long
       Dim lCntr     As Long
       Dim zPN       As String
       Dim lPNCol    As Long
    
       lPNCol = ActiveCell.Column
       lLastRow = Cells(Rows.Count, lPNCol).End(xlUp).Row
       
       For lCntr = 1 To lLastRow
          zPN = Cells(lLastRow, lPNCol)
          zPN = Replace(zPN, "-", "")
          Cells(lLastRow, lPNCol).Formula = "=" & zPN
       Next lCntr
       
    End Sub
    Now place the excel cursor in the column containing your phone numbers and press the Alt+F8.
    Select the RemoveDashes line and click Run.
    Now format the column like this.
    ExcelPhoneNoFmt.JPG
    HTH
    May the Forces of good computing be with you!

    RG

    VBA Rules!

    My Systems: Desktop Specs
    Laptop Specs


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •