How to Keep Leading Zeros in Excel CSV – 4 Easy Methods

Importance of Keeping Leading Zeros in Excel CSV

The following image showcases an example of a CSV file in Notepad.

how to keep leading zeros in excel csv

If we import this file into Excel, the dataset will be displayed as shown below.

how to keep leading zeros in excel csv

Excel omitted the leading zeros by default, which leads to an incorrect representation of the existing data.


Method 1 – Applying Cell Formatting to Keep Leading Zeros

Steps:

  • Select the ZIP Code column.
  • In the Home tab, click the arrow sign as shown in the image below.

The Format Cells dialog box will open.

how to keep leading zeros in excel csv Using Cell Formatting to Keep the Leading Zeros

  • In Format Cells, choose Special.
  • Select ZIP Code.
  • Click OK.

how to keep leading zeros in excel csv Using Cell Formatting to Keep the Leading Zeros

The ZIP Code is now in its correct format.

Follow the same steps for the Social Security Number column.

  • In Format Cells, choose Special.
  • Select Social Security Number.
  • Click OK.

how to keep leading zeros in excel csv Using Cell Formatting to Keep the Leading Zeros

All leading zeros are displayed.

Read More: [Solved]: Leading Zero Not Showing in Excel


Method 2 – Using the Text Import Wizard to Keep Leading Zeros

Step 1: Opening File in Excel

  • Go to the File tab on the Ribbon.

how to keep leading zeros in excel csv Utilizing Text Import Wizard 

The following image will be displayed

how to keep leading zeros in excel csv Utilizing Text Import Wizard 

  • Click Open.

  • elect your file.
  • Click Open.

how to keep leading zeros in excel csv Utilizing Text Import Wizard 

The Text Import Wizard dialog box will open.

how to keep leading zeros in excel csv Utilizing Text Import Wizard 

Step 2: Editing Text Import Wizard

  • In the dialogue box, choose Delimited.
  • Click Next.

how to keep leading zeros in excel csv Utilizing Text Import Wizard 

  • Check Comma.
  • Click Next.

  • Select the ZIP Code column.
  • Choose Text.

how to keep leading zeros in excel csv Utilizing Text Import Wizard 

  • Select the Social Security Number column.
  • Choose Text.
  • Click Finish.

how to keep leading zeros in excel csv Utilizing Text Import Wizard 

The Excel CSV file was imported, keeping the leading zeros.


Method 3 – Keep the Leading Zeros in Excel CSV by Using the Power Query

 

Step 1: Importing the CSV File

  • Go to the Data tab on the Ribbon.
  • Select Get & Transform Data and choose From Text/CSV.

how to keep leading zeros in excel csv Applying Power Query to Keep the Leading Zeros

  • Select your CSV file.
  • Click Import.

how to keep leading zeros in excel csv Applying Power Query to Keep the Leading Zeros

A preview is displayed.

Step 2: Transforming Data

  • Click Transform Data.

how to keep leading zeros in excel csv Applying Power Query to Keep the Leading Zeros

The Power Query Editor window will open.

how to keep leading zeros in excel csv Applying Power Query to Keep the Leading Zeros

  • In the Account Number column, click as shown below.

how to keep leading zeros in excel csv Applying Power Query to Keep the Leading Zeros

  • Select Text from the drop-down menu.

  • A dialog box will open. Choose Replace Current.

how to keep leading zeros in excel csv Applying Power Query to Keep the Leading Zeros

Zeros will be displayed in the Account Number column.

how to keep leading zeros in excel csv Applying Power Query to Keep the Leading Zeros

  • Follow the same steps for the Telephone Number column. This is the output.

Step 3: Loading Data Back to Excel Workbook

  • Click Close & Load.

how to keep leading zeros in excel csv Applying Power Query to Keep the Leading Zeros

Your CSV file was imported, keeping the leading zeros.

how to keep leading zeros in excel csv Applying Power Query to Keep the Leading Zeros

Read More: How to Add Trailing Zeros in Excel


Method 4 – Using the Excel TEXT Function to Keep Leading Zeros

Step 1: Navigating and Opening the File

how to keep leading zeros in excel csv Using TEXT Function to Keep the Leading Zeros

Step 2: Using the Text Import Wizard

  • Select Delimited.
  • Click Next.

how to keep leading zeros in excel csv Using TEXT Function to Keep the Leading Zeros

  • Check Comma.
  • Click Next.

  • Click Finish.

how to keep leading zeros in excel csv Using TEXT Function to Keep the Leading Zeros

Your data will be imported to Excel. Leading zeros are omitted.

Step 3: Using the Text Function

  • Create 2 new columns: Correct Acc No and Correct Tel No.

  • Use the following formula in E5.
=TEXT(B5,"0000000")

B5 is the cell in the Account Number column.

how to keep leading zeros in excel csv Using TEXT Function to Keep the Leading Zeros

  • Use the AutoFill feature to drag the formula across the cells you want to fill.

how to keep leading zeros in excel csv Using TEXT Function to Keep the Leading Zeros

This is the output.

  • Click on the disc icon to save the file.

how to keep leading zeros in excel csv Using TEXT Function to Keep the Leading Zeros

Step 4: Reopening the File

Step 5: Modifying Text Import in the Wizard Dialog Box

  • Select Delimited.
  • Click Next.

  • Check Tab.
  • Click Next.

how to keep leading zeros in excel csv Using TEXT Function to Keep the Leading Zeros

  • Select the Account Number column.
  • Choose Do not import column (skip).

  • Choose the same options for the Telephone Number column.

how to keep leading zeros in excel csv Using TEXT Function to Keep the Leading Zeros

  • Select Correct Acc No.
  • Choose Text.

how to keep leading zeros in excel csv Using TEXT Function to Keep the Leading Zeros

  • Select the same options for the Correct Tel No column.
  • Click Finish.

how to keep leading zeros in excel csv Using TEXT Function to Keep the Leading Zeros

The leading zeros are displayed in your CSV file.

Read More: How to Keep Leading Zero in Excel Date Format


Download Practice Workbook


Related Articles


<< Go Back to Pad Zeros in Excel | Number Format | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Zahid Hasan
Zahid Hasan

Zahid Hassan, BSc, Industrial and Production Engineering, Bangladesh University of Engineering and Technology, has worked with Exceldmy for 1.5 years. He has written 95+ articles for Exceldemy. He has worked as an Excel & VBA Content Developer. He also worked as a VBA Developer for the Template team. Currently, he is working as a Junior Software Developer for the Excel Add-in project. He is interested in Software Development, Python, VBA, VB.NET, and Data Science, expanding his expertise in... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo