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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input data into Excel from a csv file 1

Status
Not open for further replies.

AnnaWnz

MIS
Dec 10, 2002
22
0
0
NZ
Hi

Is there an easy way to open a .csv file, and write the information into Excel, without doing the File Import?

I want to open a file that has an undetermined number of rows (changes each month), with 7 columns, and write each row into an exisiting Excel worksheet, column by column.

Cheers

Anna
 
You can take one of two approaches:

1. Use workbooks.open to open the .csv file as a separate workbook, use normal Excel VBA programming to manipulate the data and, if necessary, copy it into your main workbook. After that you can just close the csv file.

2. Use sequential file access to open and read the file without having it open as a new workbook. Here you have to be a little more sure that you understand the file structure. If each line has four items, it would be something like:

open "myfile.csv" for input as #1
rownr=1
do while not eof(1)
input#1, data1, data2, data3, data4
cells(rownr,1)=data1
cells(rownr,2)=data2
cells(rownr,3)=data3
cells(rownr,4)=data4
rownr=rownr+1
loop
close #1



Rob
[flowerface]
 
Cheers.

Approach 1 is much quicker for my files (due to their size).

Thanks

Anna
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top