Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a CSV-file with VBA in a Excel spreadsheet

Status
Not open for further replies.

JohanBS

Programmer
Sep 19, 2003
4
DK
When I open a csv-file with VBA in excel it dosn't comma separate. The are put in the wrong colums

I have used the Open.Workbooks method. I think I can solve
the problem by using the format and delimiter method parameters. But I havn't been able to specify the parameters correctly and maybe it isn't the right
ways to do it anyway.
 
Hi,

Are you sure that your data in the .csv file is formatted correctly?

Open that file in Wordpad and check the offending record(s). With comma delimited data, somethimes there are commas within the data strings that mess up the import/parsing.

Skip,
Skip@TheOfficeExperts.com
 
Johan,
I viewed your .csv file and it is delimited with semicolons.

When opening it directly in Excel, the parsing is incorrect.

Open the .csv file in Wordpad from the WIndows Explored (cntl+shift+right click and select Open With...)

NOTE: Be sure that you do NOT check the box that says to use this program to open all files of this type!

In Wordpad, select all and copy

Paste in A1 in an empty worksheet

menu item -- Data/Text to columns.../select the Delimited Option Button and check semicolon checkbox

and FINISH

Your data should be parsed correctly.

Hope this helps :)

Skip,
Skip@TheOfficeExperts.com
 
Alternatively, to do it all within Excel (you can record a macro to do this) use the menu item, "Data", "Get External Data", "Import Text File"

Change the "Files of type" drop down box to "All Files" and then follow the on screen selections. "Delimited", click "Next" select "semicolon", click "Next" and then you can format the columns how you want.



Tiglet [reading]

[green]Duct tape is like the force; it has a light side & a dark side, and it holds the universe together. [/green]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top