Opening a CSV file

P

ptrowe

I am using VBA to open a CSV file. The file has a column with
part numbers which are all numeric but some start with 0.
I have placed double-quotes around the data but it still
importing it into Excel with the leading zero missing.
How do I get it to import with the leading zero still there?
 
C

Carol Torkko

Hi,
Even though the part number may be only numbers, you still
want to treat it as text. The column into which you are
loading that value is treating it as a number by default
and drops the leading zero. You need to format that
column either on the worksheet or in code to a string
format, then the leading 0 will remain.

Carol
 
T

Tom Ogilvy

Rename the file as .Txt and use the Text import wizard to mark the column
(last dialog) as Text.

You can turn on the macro recorder and get the settings so you don't have to
go through the wizard each time, however the file has to be named .txt - if
it is .csv, most versions of Excel will ignore your settings.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top