preserve leading zeros in CSV.. how?

muffins

Board Regular
Joined
Jun 18, 2002
Messages
86
Hi everyone,

I've a csv file with

,Blankman,,SomeTown, SD, 00298

When I opened this file, the text 00298 becomes 298. How can I preserve the leading zeros?

Many many thanks!!
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
When you open the file, are you using the Text Import Wizard? If so, at step 3, highlight the column with your zip code, and click the Text radio button in the top right hand section of the dialogue box.

Richard
 
Upvote 0
my file is in csv format. When I open it, whether in excel or not, there's no text import wizard.
 
Upvote 0
Hi muffins:

See if this helps ...
y030210h1.xls
ABCDE
1CityStateZipZip
2DetroitMI4822648226
3RochesterMI4830948309
4SomeTownSD29800298
5formatentries afterimporting toNumberSpecial FormatasZipCode
6
7
8
9
Sheet5
</SPAN>
 
Upvote 0
predominantly said:
What about creating a macro to apply text formatting to selected fields
in a csv file or xls file? Is this doable?
Hi Thomas:

Welcome to MrExcel Board!

Yup! ... for example for the illustration in my last post ... the following code will format all numeric entries to 5 digit ZipCode display ...
Code:
Range("C:C").NumberFormat="00000"
 
Upvote 0
Change the file extension to .txt and open from within Excel. That'll invoke the Text to Columns wizard.
 
Upvote 0
predominantly said:
What about creating a macro to apply text formatting to selected fields
in a csv file or xls file? Is this doable?

No, formatting isn't preserved in .csv or .txt files. The best you could do is place an apostrophe in front of the value(s) (e.g., '00298).
 
Upvote 0
Muffins,

Using Excel XP

• Open a new worksheet.
• Go to the Data menu | Import from External Data | Import Data.
• Navigate to your csv file, select it and then click the Open button.
• Automatically, you should now be in the “Text Import Wizard” and the radio button for “Delimiter” should be clicked.
• Click the Next button.
• Click the checkbox for “Comma”
• Click the Next button.
• In the Data Preview screen, click the column showing “00298”, and in the same dialog box, click the check box for Text (it’s under the heading “Column Data Format”).
• Click the Finish button
• In the next dialog box, choose where you want to put the data.
• Click OK.

Your formatting will be preserved.

HTH

Mike
 
Upvote 0
Ekim said:
Muffins,

Using Excel XP

• Open a new worksheet.
• Go to the Data menu | Import from External Data | Import Data.
• Navigate to your csv file, select it and then click the Open button.
• Automatically, you should now be in the “Text Import Wizard” and the radio button for “Delimiter” should be clicked.
• Click the Next button.
• Click the checkbox for “Comma”
• Click the Next button.
• In the Data Preview screen, click the column showing “00298”, and in the same dialog box, click the check box for Text (it’s under the heading “Column Data Format”).
• Click the Finish button
• In the next dialog box, choose where you want to put the data.
• Click OK.

Your formatting will be preserved.

HTH

Mike

Ekim, when a .csv file is opened the red highlighted steps will not occur!
 
Upvote 0

Forum statistics

Threads
1,214,812
Messages
6,121,704
Members
449,048
Latest member
81jamesacct

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top