Import csv containing some fields with multiple commas within quotes

Andy B

Active Member
Joined
Mar 26, 2009
Messages
338
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
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
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.
 
Upvote 0
Solution
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.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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