K
Keith R
I have a data file that I'm importing into Excel (starts as a VMS report
that is dumped into the body of an outlook message, which is then saved as a
text file). I parse it based on fixed width columns (no delimiter) the same
code is used for several different files, so the parse widths are stored in
an array.
When the file was smaller, it was plenty fast- but now the file has grown to
13MB, and it takes many minutes to import. I suspect there is a better way.
Right now I'm opening the file, grabbing each line, parsing it, then pasting
it to the worksheet (code below).
Can someone recommend the best practice to do this as quickly as possible?
I've already got calculations set to manual, and screenupdating to false. I
was considering loading the entire file first, then parsing each line in
memory, then pasting all the lines, but while that groups like operations
together, I wasn't sure how it would save time if all of the same operations
were still being done a line at a time.
Thanks!!
Keith
Open LongFN For Input As #1
Do While Not EOF(1)
Line Input #1, LineofText
If Len(LineofText) > 3 Then
rw = rw + 1
' now parse LineofText according to the column
widths and
' put the values in an array.
For j = 1 To 30
ParseStart = TotalFileArray(WhichFile, j)
ParseEnd = TotalFileArray(WhichFile, j + 1)
If ParseEnd > 0 Then
TotalDataArray(WhichFile, j, rw) =
Trim(Mid(LineofText, ParseStart, ParseEnd - ParseStart))
ConvertCol (j)
mywrksht.Range(Usecol & Trim(Str(rw))).Value
= TotalDataArray(WhichFile, j, rw)
End If
Next
End If
Loop
Close #1 'Close the file
that is dumped into the body of an outlook message, which is then saved as a
text file). I parse it based on fixed width columns (no delimiter) the same
code is used for several different files, so the parse widths are stored in
an array.
When the file was smaller, it was plenty fast- but now the file has grown to
13MB, and it takes many minutes to import. I suspect there is a better way.
Right now I'm opening the file, grabbing each line, parsing it, then pasting
it to the worksheet (code below).
Can someone recommend the best practice to do this as quickly as possible?
I've already got calculations set to manual, and screenupdating to false. I
was considering loading the entire file first, then parsing each line in
memory, then pasting all the lines, but while that groups like operations
together, I wasn't sure how it would save time if all of the same operations
were still being done a line at a time.
Thanks!!
Keith
Open LongFN For Input As #1
Do While Not EOF(1)
Line Input #1, LineofText
If Len(LineofText) > 3 Then
rw = rw + 1
' now parse LineofText according to the column
widths and
' put the values in an array.
For j = 1 To 30
ParseStart = TotalFileArray(WhichFile, j)
ParseEnd = TotalFileArray(WhichFile, j + 1)
If ParseEnd > 0 Then
TotalDataArray(WhichFile, j, rw) =
Trim(Mid(LineofText, ParseStart, ParseEnd - ParseStart))
ConvertCol (j)
mywrksht.Range(Usecol & Trim(Str(rw))).Value
= TotalDataArray(WhichFile, j, rw)
End If
Next
End If
Loop
Close #1 'Close the file