+ Reply to Thread
Results 1 to 9 of 9

Leading Zero's Problem

Hybrid View

  1. #1
    Registered User
    Join Date
    09-12-2011
    Location
    Spring Lake, Mi
    MS-Off Ver
    Excel 2010
    Posts
    15

    Unhappy Leading Zero's Problem

    I got some awesome help the first time I asked for it on a previous problem so thought I would try again.. Any help you can give me will be much appreciated.

    I have 11000 cells with 1 digits , 2 digits , 3 digits, 4 digits, 5 digits, 6 digits and 7 digit number.

    I am looking for a formula or macro to add the following:

    6 zero's before 1 digit,
    5 zero's before 2 digit
    4 zero's before 3 digits
    3 zero's before 4 digits
    2 zero's before 5 digits
    1 zero before 6 digits

    Every cell in the W/O column needs to have 7 digits with 0's at the beginning of the numbers if the number is less than zero. I will then create a csv file so I can import it into the database. It is a requirement that each number have 7 digits so this is the only way I can think of doing it.

    I attached a sample file but if the macro works on this I am sure I can run it against a file with 11,000 cells in the W/O Number Column.

    Thanks in advanced for help..
    Attached Files Attached Files
    Last edited by bzenker; 09-25-2011 at 01:56 AM.

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: Leading Zero's Problem

    Hello,

    Insert a new (helper) column and use this formula:

    =TEXT(A2,"0000000")

    Copy down.

    Copy the helper column, then use Paste Special > Values to paste the values into column A.

    Save as CSV.

    cheers,

  3. #3
    Registered User
    Join Date
    09-12-2011
    Location
    Spring Lake, Mi
    MS-Off Ver
    Excel 2010
    Posts
    15

    Smile Re: Leading Zero's Problem

    Worked Pefectly... Very Cool...

    Thanks for your quick response.

  4. #4
    Registered User
    Join Date
    09-12-2011
    Location
    Spring Lake, Mi
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Leading Zero's Problem

    Teylyn,

    One issue I am having is when I save it as a csv file I loose the formating. Why would that be? How do I keep the formating after saving as a csv file?

    Thanks again,

  5. #5
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,352

    Re: Leading Zero's Problem

    Hi bzenker,

    I think she suggested you save the column that had all those leading zeros over the top of your original values. If you did this, then you would have text in the original coloumns and wouldn't need any formats.

    The other answer is that if you save as CSV, formats are not saved.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Leading Zero's Problem

    CSV files are text files, and differ from txt files only in that the csv extension serves to indicates that data values are delimited by commas. Text files don't store formatting.
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Registered User
    Join Date
    09-12-2011
    Location
    Spring Lake, Mi
    MS-Off Ver
    Excel 2010
    Posts
    15

    Question Re: Leading Zero's Problem

    I setup a test excel file like you suggested. It is attached so you can check it out to see if I have it correct. The cell is setup as text and not a number. I save it as a csv file and loose the formating. Am I doing something wrong when saving the file?

    Thanks again..
    Attached Files Attached Files

  8. #8
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Leading Zero's Problem

    When you open a csv file, excel recognized that these are numbers rather than text and converts them back a number. One option would be to save them as tab-delimited text file (*.txt) and when you open the file use the data import wizard to designate the import as text rather than the default (which is general).

    Hope this helps.

    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  9. #9
    Registered User
    Join Date
    09-12-2011
    Location
    Spring Lake, Mi
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Leading Zero's Problem

    That makes sense.. I saved the file as a .csv file and when I open it with Wordpad it has the leading zero's... I agree with you it looks like Excel is converting them back to a number when opening it; however, it looks like Excel is saving it with the leading zeros so I do believe the data importer will recognize it... .txt file should work..

    Thanks.. I believe I am all set..

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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