+ Reply to Thread
Results 1 to 3 of 3

How to Keep Leading Zeros in CSV File Format?

  1. #1
    Registered User
    Join Date
    10-04-2019
    Location
    Charlotte, NC
    MS-Off Ver
    MS Office 365 32-bit
    Posts
    3

    How to Keep Leading Zeros in CSV File Format?

    Hello!

    I am trying to have a column of numbers include leading zeros so they all contain six digits.

    Example Attached

    1. I want all numbers Column A to have six digits (if they already have 5 digits, add 1 leading zero, 4 digits = 2 leading zeroes, and so on).
    2. When I follow a website I found with tips for this process (highlight cells, format cells, category - custom, type 6 0's under type, click OK) - the format of the cell automatically changes to "Special", not custom).
    3. Then, when I close the file and re-open it, the numbers are back to the original digits (4 or 2 or whatever) and not the 6 digits with the leading zeros.

    Thank you for any help you can provide!

    Doc1.docx

  2. #2
    Administrator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs
    MS-Off Ver
    MS Office 365 Version 2211 (Build 15813.20002) Win 11 Home 64 Bit
    Posts
    22,079

    Re: How to Keep Leading Zeros in CSV File Format?

    crossposted: https://www.mrexcel.com/board/thread...ormat.1115942/

    Rule 03: Cross-posting Without Telling Us

    Your post does not comply with Rule 3 of our Forum RULES. Do not cross-post your question on multiple forums without telling us about your threads on other forums.

    Post a link to any other forums where you have asked the same question.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Read this to understand why we ask you to do this.

    I have added the crosspost reference for you today. Please comply with this and all our rules in the future
    Alan


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    14,743

    Re: How to Keep Leading Zeros in CSV File Format?

    Exactly what are you trying to do here? I find that these questions usually fall into one of two camps:
    1) I have an Excel file, I want to save the file in a text or csv format where numbers are stored with 6 digits including leading zeros. This file then goes to another program.
    2) I have a text or csv file with 6 digit numbers including leading zeros. I need to import that into Excel and retain the leading zeros.

    In my experience, Excel does a good job when saving a text file of saving exactly as displayed. So, if you have cells formatted as "000000" (or similar which correctly displays the leading zeroes), then Excel will write that text to the text file when saving as csv/text. If saving the csv file is the main concern here, and reopening the file is trying to verify that Excel saved the text correctly, I recommend reopening in a text editor rather than Excel to see exactly what Excel saved. If viewing the file in a text editor reveals something incorrect in the way Excel saved the text file, then we would need to understand how you had it set up, what happened when Excel saved the text file, and what you need done differently.

    As noted by someone on the other board, csv/text files do not contain any Excel formatting information. Since Excel's first inclination is to interpret text as a number, when it opens a csv and sees 003456 in a field, it interprets it as a number and drops the leading zeros (as a number, there is not difference between 003456 and 3456). You as the user/programmer need to understand your import requirements well enough to tell Excel how to handle those fields on or after import. Exactly what that looks like depends in large part on what you are trying to do with these values in Excel.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

+ 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. How do i add leading zeros in hh:mm:ss format?
    By anniea88 in forum Excel General
    Replies: 9
    Last Post: 10-22-2021, 03:34 AM
  2. Format data with leading zeros
    By linda1964 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 08-16-2016, 07:45 PM
  3. Leading Zeros in Numeric Format
    By zakel in forum Excel General
    Replies: 2
    Last Post: 04-12-2012, 04:45 PM
  4. Format for Leading Zeros
    By DavidW in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-19-2006, 04:01 PM
  5. Format a cell to keep leading zeros.
    By Shadyhosta in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 07-27-2005, 11:37 AM
  6. Replies: 1
    Last Post: 05-04-2005, 02:06 PM
  7. leading zeros in text format
    By BigBrook in forum Excel General
    Replies: 3
    Last Post: 02-04-2005, 08:06 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