Ideas for quicker way to populate adjacent cells with array elemen
Is there a reason you couldn't just use:
workbooks.open filename:="C:\myfolder\inputname.csv"
If you want more control of individual field formats, rename your .csv file to
..txt and then record a macro when you do file|open.
I would think that opening multiple files this way (and combining later) would
be quicker (even noticeable when the number of lines gets larger).
Another option would be to use an old DOS command to combine your .csv files
into a single file, then import that once.
If the files are in the same folder and all files named *.csv should be
combined:
Shell to DOS
traverse to that folder
copy *.csv all.txt
Then exit the command prompt.
Back to excel and import All.Txt.
===
You could even mechanize this in your code via the shell command (and maybe an
application.wait to make sure the files are combined before continuing).
Bing wrote:
Hi,
I written a macro to read in line by line multiple CSV files of varying
lengths.
Can anyone suggest a faster way in terms of runtime execution time to speed
this code up?
ie. I thought of reading in multiple lines in bulk to reduce I/O but VBA
doesn't seem to have a bulk read mode.
Basically i do the following:
Dim columnArrays as Variant
Dim newColumnArray as Variant
.
.
Do until EOF(inputFile)
Line Input #inputFile, inputLine
columnArray = Split(inputLine, ",")
....merge/massage/apply functions to certain columns in columnArray
and copy into newColumnArray
for i = 0 to Ubound(newColumnArray)
aRange.Offset(0,i).Value = newColumnArray(i)
next i
set aRnage = aRange.Offset(1,0)
Loop
Thanks to everyone for their valuable insights.
--
Dave Peterson
|