Re: load/parse large text file
- From: "Keith R" <fake_address@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 6 Apr 2007 16:10:47 -0400
I've updated my code to read the entire file first, one line at a time into
an array (wow, that does seem faster, now down to about 30 seconds), parse
each line in memory (almost instant), and now I'm ready to set the worksheet
range equal to the array. I now have a few more questions. Using Excel 2003.
1) I'm never sure how many rows the data file will have, so I start with an
oversized array so I won't have to continually redim/preserve. My array is
dimmed as testarray(1 To 32, 1 To 50000). I'm not worried about memory, so
is it ok to dim an oversized array or will that cause some other problem I
don't know about yet?
2) I'm not sure how many rows are in the data file in advance, so I
increment a counter variable, rw, as I read each line. what is the
appropriate syntax to set a range equal to the array? I tried the following,
but it didn't work out.
Sheet1.range("A1") = testArray() 'in case Excel could autoexpand the range
to match the array size
Sheet1.range("A1:AF50000") = testArray() 'to paste the whole array at once,
risk overwriting surrounding areas with blanks
Sheet1.range("A1").resize(rw,32) = testArray() ' to paste only the same
number of rows as were in the raw file?
I keep getting a type mismatch error :(
3) I'm actually reading the raw file into (32, 1 to 50000), then parsing
each string back into fields 1-31. When I write the range back, is there an
easy way to just write the first 31 fields of the array? My alternative is
to erase field 32 before writing the whole array (probably with a
redim/preserve to make the array smaller), but I wasn't sure if I could just
write the desired section of the array- it might be useful if I later find
out I need to go back to the original string for any reason.
Many thanks!!
Keith
"Peter Grebenik" <pgrebug@xxxxxxxxx> wrote in message
news:1175878841.505173.36340@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Keith
My understanding is that each "write" to the spreadsheet carries an
overhead.
So, you could try parsing something like 100 rows of data into a
variant array and then writing that to the spreadsheet by simply
setting the appropriate range equal to the array. This will also cut
out your call to your ConvertCol routine.
HTH
Peter
.
- Follow-Ups:
- Re: load/parse large text file
- From: Peter T
- Re: load/parse large text file
- From: Peter Grebenik
- Re: load/parse large text file
- References:
- load/parse large text file
- From: Keith R
- Re: load/parse large text file
- From: Peter Grebenik
- load/parse large text file
- Prev by Date: calculate hours using start time & end time, excluding weekends
- Next by Date: Re: auto filter macro
- Previous by thread: Re: load/parse large text file
- Next by thread: Re: load/parse large text file
- Index(es):
Relevant Pages
|