+ Reply to Thread
Results 1 to 6 of 6

Leading Zero's

  1. #1
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Leading Zero's

    Is there a consistant way to format numbers to ensure leading zero's remain intact. I have a series of six digit numbers to which I've applied the 'custom format' 000000 to make sure all the numbers that should have leading zero's appear as six digit numbers, however, if I extract these numbers to a different worksheet, some maintain the formatting, others don't seems to and if I view the format it sometimes automatically changes from 'custom' to a 'special' format for a particular county!

    Sometimes a number with leading zero's formatted as 'General' maintains the zero's, other times it doesn't... I can take 001234 formatted as general and copy and paste it and the leading zero's remain intact, (why, I have no idea) but I can equally type the number 001234 also formatted as 'General' at the cell looses the leading zero's!

    My numbers may look like this:

    123456
    003456
    012345
    123400

    and I need to avoid this when copied and pasted etc

    123456
    3456
    12345
    123400

    I need a guaranteed way of ensuring all my numbers maintain the six digit format and those that have leading zero's maintain them (I've applied the custom format 000000 to all my numbers), is there any surefire way to do this?

    Many thanks

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: Leading Zero's

    the only way 001234 will retain the leading zero's after a copy or format to general, is if it is not a number/value in the 1st place. It is probably text that just looks like a number - test it with =isnumber(cell-ref) FALSE will tell you its text

    in fact, that may be a way for you to maintain the leading zeros (make them text), and then just add 0 or * 1 to get them back to numbers?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Leading Zero's

    Maybe you can format the items as text.

    You won't be able to count with it, but i don't know if that's a problem.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  4. #4
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: Leading Zero's

    Use Copy then Right click -Paste Special and select " Formulas & Number formatting" option -

  5. #5
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    Re: Leading Zero's

    =TEXT($A$1,"000000") How about a formula?

    Set it equal to the cells that have the numbers, then copy the cells with the formula and paste values...play around with the absolute value to suit your needs
    Last edited by VBA FTW; 01-10-2013 at 10:03 PM.

  6. #6
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    Re: Leading Zero's

    Quote Originally Posted by oeldere View Post
    Maybe you can format the items as text.

    You won't be able to count with it, but i don't know if that's a problem.
    What about the COUNTA function?

+ 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