+ Reply to Thread
Results 1 to 3 of 3

Problems with leading zeroes when converting to a .csv file

  1. #1
    Registered User
    Join Date
    05-06-2015
    Location
    Daytona Beach, FL
    MS-Off Ver
    2010 Professional
    Posts
    1

    Problems with leading zeroes when converting to a .csv file

    I have a database over 4600 lines long that was created in Excel. My columns labelled SKU and UPC are formatted as text. When I convert my excel file to a .csv file I lose the leading zeroes in the SKU column. Example 00325 converts to 325. My UPC column converts to a scientific number. Example 039897733890 becomes 3.99+10. When I convert the scientific back to text I get 39897733890. Are there settings in Excel that correct this issue? Approximately 60% of my rows have leading zeroes in the SKU and/or UPC coulmns.

    Thanks for any assistance with this issue.

  2. #2
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Problems with leading zeroes when converting to a .csv file

    Here is an example of how you can restore the missing leading zeros.

    If your original number is 12 characters long and you lost one leading zero use TEXT function with 12 zeros format

    =TEXT(A1,"000000000000")

    Row\Col
    A
    B
    1
    39897733890 039897733890
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  3. #3
    Forum Expert
    Join Date
    05-01-2014
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    1,795

    Re: Problems with leading zeroes when converting to a .csv file

    Quote Originally Posted by tensetoast View Post
    When I convert my excel file to a .csv file I lose the leading zeroes in the SKU column. Example 00325 converts to 325. My UPC column converts to a scientific number. Example 039897733890 becomes 3.99+10.
    Quote Originally Posted by AlKey View Post
    Here is an example of how you can restore the missing leading zeros. If your original number is 12 characters long and you lost one leading zero use TEXT function with 12 zeros format
    =TEXT(A1,"000000000000")
    You misunderstand the problem. And writing the data as text does not solve it.

    If the cells display leading zeros in Excel, they are written to the CSV file with leading zeros, regardless of whether the Excel values are text or numeric.

    You can verify that by opening the CSV file in Notepad or the equivalent.

    The problem arises when you open the file directly in Excel. Excel tries to interpret the data as numeric. It does not matter what type the data was when it was written to the CSV file. Remember: a CSV file is just plain ASCII (text); there is no format or type information.

    (And by the way, it does not help to surround data with double-quotes. Excel still interprets the data the same as if there were no double-quotes.)

    We see 3.99+10 for 039897733890 because the cell is formatted as General, and such large numbers are displayed in Scientific form (although the cell format remains General).

    And by the way, that bodes ill for CSV data that appear to be numbers with more than 15 significant digits. In that case, Excel truncates the data after 15 significant digits, filling in with zeros. For example, 001234567890123456 will be interpreted as the number 1234567890123450, displayed as 1.23457E+15.

    One possible remedy is to import the CSV (Get External Data / From Text) instead of opening it directly. The Import Text File wizard gives us the opportunity to treat entire columns as text instead of numeric data.

    Of course, that is useful only if all of a column can be treated as text.

    In the case of columns with mixed types of data, the only remedy is write a VBA routine to import the data, relying on the VBA algorithm to treat some input as text.
    Last edited by joeu2004; 05-07-2015 at 04:19 AM. Reason: cosmetic

+ 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. Add zeroes within dates (NOT leading zeroes)
    By anthony19 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-13-2012, 04:08 PM
  2. Leading Zeroes & XML
    By jlhart76 in forum Excel General
    Replies: 4
    Last Post: 06-03-2009, 08:23 PM
  3. Leading Zeroes In Decimals
    By johnph77 in forum Excel General
    Replies: 3
    Last Post: 05-15-2009, 10:04 AM
  4. Converting xls to CSV file - dropping leading 0s
    By vanjohnson in forum Excel General
    Replies: 1
    Last Post: 07-05-2006, 02:50 PM
  5. [SOLVED] Leading Zeroes
    By Ken in forum Excel General
    Replies: 1
    Last Post: 10-07-2005, 11:05 AM

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