+ Reply to Thread
Results 1 to 7 of 7

Phone Number formatting

  1. #1
    Forum Contributor
    Join Date
    04-27-2006
    Location
    Cayman Islands
    Posts
    379

    Phone Number formatting

    Hi all, I have a cell that NEEDS to be of the following format:

    0#### ######

    I have set this up under formatting, custom... and when I type a number like this...

    01304999999 I get the result 01304 999999 PERFECT!

    Unfortunately if I type this....

    01304 999 999 I get this result 01304 999 999 which ain't good as it mucks up my Macro, whih incidentally is this...

    appWD.ActiveDocument.Bookmarks("PMTelephone").Range = Format(strPMTelephone, "0#### ######")

    Any ideas?

  2. #2
    Toppers
    Guest

    RE: Phone Number formatting

    Chris,
    Maybe a Worksheet event to format the cell; the following is a
    "Starter" but maybe needs code to check length of input and check target
    address if just one cell.

    Private Sub Worksheet_Change(ByVal Target As Range)
    On Error GoTo wsexit
    If Target.Column <> 1 Then GoTo wsexit '<==== not coulmn A
    Application.EnableEvents = False
    Target.Value = Format(Replace(Target.Value, " ", ""), "0#### ######")
    wsexit:
    Application.EnableEvents = True
    End Sub

    "ChrisMattock" wrote:

    >
    > Hi all, I have a cell that NEEDS to be of the following format:
    >
    > 0#### ######
    >
    > I have set this up under formatting, custom... and when I type a number
    > like this...
    >
    > 01304999999 I get the result 01304 999999 PERFECT!
    >
    > Unfortunately if I type this....
    >
    > 01304 999 999 I get this result 01304 999 999 which ain't good as it
    > mucks up my Macro, whih incidentally is this...
    >
    > appWD.ActiveDocument.Bookmarks("PMTelephone").Range =
    > Format(strPMTelephone, "0#### ######")
    >
    > Any ideas?
    >
    >
    > --
    > ChrisMattock
    > ------------------------------------------------------------------------
    > ChrisMattock's Profile: http://www.excelforum.com/member.php...o&userid=33912
    > View this thread: http://www.excelforum.com/showthread...hreadid=554500
    >
    >


  3. #3
    Toppers
    Guest

    RE: Phone Number formatting

    Chris,
    Maybe a Worksheet event to format the cell; the following is a
    "Starter" but maybe needs code to check length of input and check target
    address if just one cell.

    Private Sub Worksheet_Change(ByVal Target As Range)
    On Error GoTo wsexit
    If Target.Column <> 1 Then GoTo wsexit '<==== not coulmn A
    Application.EnableEvents = False
    Target.Value = Format(Replace(Target.Value, " ", ""), "0#### ######")
    wsexit:
    Application.EnableEvents = True
    End Sub

    "ChrisMattock" wrote:

    >
    > Hi all, I have a cell that NEEDS to be of the following format:
    >
    > 0#### ######
    >
    > I have set this up under formatting, custom... and when I type a number
    > like this...
    >
    > 01304999999 I get the result 01304 999999 PERFECT!
    >
    > Unfortunately if I type this....
    >
    > 01304 999 999 I get this result 01304 999 999 which ain't good as it
    > mucks up my Macro, whih incidentally is this...
    >
    > appWD.ActiveDocument.Bookmarks("PMTelephone").Range =
    > Format(strPMTelephone, "0#### ######")
    >
    > Any ideas?
    >
    >
    > --
    > ChrisMattock
    > ------------------------------------------------------------------------
    > ChrisMattock's Profile: http://www.excelforum.com/member.php...o&userid=33912
    > View this thread: http://www.excelforum.com/showthread...hreadid=554500
    >
    >


  4. #4
    Toppers
    Guest

    RE: Phone Number formatting

    Chris,
    Maybe a Worksheet event to format the cell; the following is a
    "Starter" but maybe needs code to check length of input and check target
    address if just one cell.

    Private Sub Worksheet_Change(ByVal Target As Range)
    On Error GoTo wsexit
    If Target.Column <> 1 Then GoTo wsexit '<==== not coulmn A
    Application.EnableEvents = False
    Target.Value = Format(Replace(Target.Value, " ", ""), "0#### ######")
    wsexit:
    Application.EnableEvents = True
    End Sub

    "ChrisMattock" wrote:

    >
    > Hi all, I have a cell that NEEDS to be of the following format:
    >
    > 0#### ######
    >
    > I have set this up under formatting, custom... and when I type a number
    > like this...
    >
    > 01304999999 I get the result 01304 999999 PERFECT!
    >
    > Unfortunately if I type this....
    >
    > 01304 999 999 I get this result 01304 999 999 which ain't good as it
    > mucks up my Macro, whih incidentally is this...
    >
    > appWD.ActiveDocument.Bookmarks("PMTelephone").Range =
    > Format(strPMTelephone, "0#### ######")
    >
    > Any ideas?
    >
    >
    > --
    > ChrisMattock
    > ------------------------------------------------------------------------
    > ChrisMattock's Profile: http://www.excelforum.com/member.php...o&userid=33912
    > View this thread: http://www.excelforum.com/showthread...hreadid=554500
    >
    >


  5. #5
    Pete_UK
    Guest

    Re: Phone Number formatting

    Hi Chris,

    the STD code of a (UK) phone number is not always 5 characters - you
    can have 4, 5 6 or 7, and phone numbers themselves can vary in length -
    how would you want to display 118118, for example?

    I find it better to treat phone numbers as text, so the leading zero(s)
    are preserved and to just display them as is without any extra spaces.
    I know this is not what you are asking, but ...

    hope this helps.

    Pete

    ChrisMattock wrote:
    > Hi all, I have a cell that NEEDS to be of the following format:
    >
    > 0#### ######
    >
    > I have set this up under formatting, custom... and when I type a number
    > like this...
    >
    > 01304999999 I get the result 01304 999999 PERFECT!
    >
    > Unfortunately if I type this....
    >
    > 01304 999 999 I get this result 01304 999 999 which ain't good as it
    > mucks up my Macro, whih incidentally is this...
    >
    > appWD.ActiveDocument.Bookmarks("PMTelephone").Range =
    > Format(strPMTelephone, "0#### ######")
    >
    > Any ideas?
    >
    >
    > --
    > ChrisMattock
    > ------------------------------------------------------------------------
    > ChrisMattock's Profile: http://www.excelforum.com/member.php...o&userid=33912
    > View this thread: http://www.excelforum.com/showthread...hreadid=554500



  6. #6
    Forum Contributor
    Join Date
    04-27-2006
    Location
    Cayman Islands
    Posts
    379
    Thanks Pete, that is an excellent point.... annoying.... but excellent point. Lol. Text it is.

  7. #7
    Pete_UK
    Guest

    Re: Phone Number formatting

    Thanks for feeding back, Chris.

    Pete

    ChrisMattock wrote:
    > Thanks Pete, that is an excellent point.... annoying.... but excellent
    > point. Lol. Text it is.
    >
    >
    > --
    > ChrisMattock
    > ------------------------------------------------------------------------
    > ChrisMattock's Profile: http://www.excelforum.com/member.php...o&userid=33912
    > View this thread: http://www.excelforum.com/showthread...hreadid=554500



+ 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