+ Reply to Thread
Results 1 to 5 of 5

Format numbers in a cell according to what they start with

  1. #1
    Registered User
    Join Date
    07-29-2013
    Location
    Kenilworth, England
    MS-Off Ver
    Excel 2010
    Posts
    3

    Format numbers in a cell according to what they start with

    I'm trying to force UK telephone numbers to display correctly. All are 11 digits, but there are 3-digit, 4-digit and 5-digit area codes, and this affects subsequent formatting. There are 3 main ways of displaying phone numbers:

    • 020 **** ****
    • 01** *** ****
    • 01*** ******

    I think it may be an IF statement that will do the trick, along the lines of (with apologies for lack of syntax):

    {IF <CELL> starts "02", display format *** **** ****} OR {IF <CELL> starts "0121","0131","0141","0151" (etc), display format **** *** ****} OR {ELSE display format ***** ******}

    Is this possible in Excel?

    Thank you!

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Format numbers in a cell according to what they start with

    its a bit more involved than that
    http://en.wikipedia.org/wiki/List_of...United_Kingdom
    but this will cover most
    =IF(OR(LEFT(SUBSTITUTE(A1," ",""),4)={"0113","0114","0115","0116","0117","0118","0121","0131","0141","0151","0161","0191"}),TEXT(SUBSTITUTE(A1," ","")+0,"0000 000 0000"),IF(LEFT(SUBSTITUTE(A1," ",""),3)="020",TEXT(SUBSTITUTE(A1," ","")+0,"000 0000 0000"),TEXT(SUBSTITUTE(A1," ","")+0,"00000 000000")))
    Last edited by martindwilson; 07-29-2013 at 07:32 AM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Registered User
    Join Date
    07-29-2013
    Location
    Kenilworth, England
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Format numbers in a cell according to what they start with

    Thanks very much, Martin. I don't understand it (yet) but it works, which is the important thing.

    I know the UK telephone number formats are complicated, but the ones on my list are all in one of those 3 categories.

    This is a stupid question, I know, but I'm going to ask it anyway.

    Does the formula have to be in a different cell from the one where the data is entered? (I'm sure the answer is yes, given "circular reference" message that appears if it's in the data entry cell.)

    Thanks again for your helpful and speedy response.

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Format numbers in a cell according to what they start with

    Yes but once you have all the new values you can copy the lot
    then paste back as paste/special/values to remove the formula

  5. #5
    Registered User
    Join Date
    07-29-2013
    Location
    Kenilworth, England
    MS-Off Ver
    Excel 2010
    Posts
    3

    Thumbs up Re: Format numbers in a cell according to what they start with

    Thanks, Martin, for all your help, and especially for your polite and helpful reply to my last question.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] VBA to return the column numbers of the start and finish of a merged cell? RANDOM!
    By JamesGoulding85 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-28-2013, 01:32 PM
  2. Insert Numbers Counting From 1 upwards Until It Reaches A Blank Cell Then Start Again
    By TkdKidSnake in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-22-2013, 02:26 PM
  3. Trying to determine start and end cell numbers
    By Forgemaster66 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-08-2013, 11:50 AM
  4. format to start new line in a single text cell?
    By Pete1000 in forum Excel General
    Replies: 2
    Last Post: 11-08-2007, 03:27 PM
  5. [SOLVED] cell format: numbers won't be numbers
    By Craig Fletcher in forum Excel General
    Replies: 12
    Last Post: 05-01-2006, 06:10 PM

Tags for this Thread

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