+ Reply to Thread
Results 1 to 2 of 2

Can i Format Phone Numbers like this

Hybrid View

  1. #1
    J.wills
    Guest

    Can i Format Phone Numbers like this

    Hi,

    I just want the numbers to be displayed in this format (630) 123-1234

    I have an input mask for a field call Cell Phone:
    !\(999") "000\-0000;0;_

    When I use that field to print on my report, I'm getting this to display?
    (999) 000-0000(630) 123-1234

    please give some suggestions.

    Thank you!

  2. #2
    Forum Administrator ExlGuru's Avatar
    Join Date
    03-17-2009
    Location
    India
    MS-Off Ver
    2003,2007
    Posts
    222

    Re: Can i Format Phone Numbers like this

    Try this code this code is basically for converting the phone number format like this (###) ###-####.

    Sub Format_Phone()

    ' converts most default phone columns to US/CAN standard (###) ###-####

    Dim TheRg As Range
    Dim cCell As Range
    On Error Resume Next
    
        Selection.Replace What:="1", Replacement:="1 ", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        Selection.Replace What:="2", Replacement:="2 ", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        Selection.Replace What:="3", Replacement:="3 ", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        Selection.Replace What:="4", Replacement:="4 ", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        Selection.Replace What:="5", Replacement:="5 ", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        Selection.Replace What:="6", Replacement:="6 ", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        Selection.Replace What:="7", Replacement:="7 ", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        Selection.Replace What:="8", Replacement:="8 ", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        Selection.Replace What:="9", Replacement:="9 ", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        Selection.Replace What:="0", Replacement:="0 ", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
    
    Set TheRg = Selection.SpecialCells(xlCellTypeConstants, 2)
    If TheRg Is Nothing Then MsgBox "No Text!", vbCritical: Exit Sub
    On Error GoTo 0
    
      TheRg.Select
      
        Selection.Replace What:="=", Replacement:="", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=True
      
        Selection.Replace What:="/", Replacement:="", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=True
      
        Selection.Replace What:="(", Replacement:="", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=True
            
        Selection.Replace What:=".", Replacement:="", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=True
            
        Selection.Replace What:=")", Replacement:="", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=True
        
        Selection.Replace What:="-", Replacement:="", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=True
        
        Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=True
            
        For Each cCell In TheRg
            If IsNumeric(cCell.Value) Then
                cCell.Value = "(" & Left(cCell.Value, 3) & ") " & Mid(cCell.Value, 4, 3) & "-" & Right(cCell.Value, 4)
            End If
        Next
        
        Selection.Replace What:="() -", Replacement:="", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=True
            
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1