Import csv containing some fields with multiple commas within quotes

Andy B

Active Member
Joined
Mar 26, 2009
Messages
336
Hi, I am trying to pull a csv file into a worksheet within a workbook and despite long searching have not yet found a solution.

A single line would typically be in the following format:


407,"2018-07-24 12:21:08",processing,130.00,paypal,fist name,surname,name@email.co.uk,07123123456,"Hi, this is a comment, with multiple commas",,Name1,Name2,6:15,Premier,,

As you can see, some fields may be blank, some will be in quotation marks and contain several commas that should not be delimiters.

When I double click the file to open it in Excel it comes through fine but of course I lose leading zero's from telephone numbers etc. Every VBA import routine I have tried splits the file at the commas within the quotes. I have tried renaming the extension to .txt and using the text import wizard but this does the same.

I would be grateful if anyone has a solution to this.

Many thanks
 

Some videos you may like

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Joyner

Well-known Member
Joined
Nov 15, 2005
Messages
1,202
I'm not sure what VBA import routine you are using, but if you use the import wizard, you should be able to set each field format correctly, and also set the Text Qualifier (your quotes) so the comment is not delimited.

Do you have Power Query (Get & Transform)? That may work better for you, it is easier and more intuitive and more capable than other Excel import tools.
 

Andy B

Active Member
Joined
Mar 26, 2009
Messages
336
I'm not sure what VBA import routine you are using, but if you use the import wizard, you should be able to set each field format correctly, and also set the Text Qualifier (your quotes) so the comment is not delimited.

Do you have Power Query (Get & Transform)? That may work better for you, it is easier and more intuitive and more capable than other Excel import tools.
The import wizard doesn't have enough flexibility but Power Query worked perfectly and I can just refresh the query with a macro which is exactly what I wanted.

Thanks for your help.
 

Watch MrExcel Video

Forum statistics

Threads
1,099,916
Messages
5,471,487
Members
406,766
Latest member
Parasoner

This Week's Hot Topics

Top