Written by Allen Wyatt (last updated May 10, 2025)
This tip applies to Excel 97, 2000, 2002, and 2003
John wrote concerning a problem with handling leading zeros in CSV files. He creates CSV files destined for import into an accounting program, but has problems with the CSV files if he needs to first reload the CSV into Excel to correct any mistakes in the file.
Actually, there are two things that need to be checked here. First, is Excel putting the leading zeros in the CSV file it initially creates? Second, is it maintaining the zeros in the CSV file when you reload it and then resave it? These are two separate issues.
You can check the first issue easily enough. All you need to do is rename the CSV file so it has a TXT extension, then you can load it into a text editor, such as Notepad. There you can examine the actual CSV file, as created by Excel, to make sure that everything is in the format you expect. If it is not—for instance, there are no leading zeros where you need them—then you need to be concerned with how Excel is creating the CSV file in the first place.
You need to check whether there are leading zeros in the original Excel information. If there are, and they are displayed, then you need to make sure that the column in which the data is contained is formatted as Text in the Number tab of the Format Cells dialog box. If they are not, then you need to format the cells using a Custom number format that displays the zeros. In both of these cases, the leading zeros will be included in the CSV file created by Excel.
This brings us to the second issue. When you load a CSV file into Excel, it tries to determine the format of the data being loaded. You probably noticed when you loaded your CSV file in Notepad that even though Excel includes leading zeros in the output file, there are no quotes around the field itself. This means that Excel automatically recognizes the field as a number when importing it. By default, then, the number is displayed using one of the number fields, thereby expunging any leading zeros in what Excel displays.
The way around this problem should be fairly obvious based on information earlier in this tip—somehow you need to get Excel to recognize the incoming information as text so that it treats the leading zeros as significant. The quickest way to do this is to follow these steps, prior to loading the CSV file:
Figure 1. The Text Import Wizard.
Now you can do your work in Excel, as desired, and again save your data in CSV format. (You will, however, need to use Save As rather than simply using Save.) The leading zeros will be included in the data that is saved.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2588) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Handling Leading Zeros in CSV Files.
Dive Deep into Macros! Make Excel do things you thought were impossible, discover techniques you won't find anywhere else, and create powerful automated reports. Bill Jelen and Tracy Syrstad help you instantly visualize information to make it actionable. You’ll find step-by-step instructions, real-world case studies, and 50 workbooks packed with examples and solutions. Check out Microsoft Excel 2019 VBA and Macros today!
When you get a bunch of raw data into Excel from an external source, it isn't going to be formatted to your liking. The ...
Discover MoreGetting rid of formatting from a cell or group of cells can be done using several different techniques. This tip ...
Discover MoreDo you want to copy formats from one worksheet to another? You can do so easily by using the Format Painter. It even ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments