L
larrydave
Hello;
I have a macro that imports a large text file into excel; it puts the data
in every fourth column after column A (starting in A2) fills up); last week
it was running fairly fast - it took maybe 20-30 seconds to read over 70,000
lines. This week, it has slowed down considerably and I didn't make any code
changes. Tonight after letting it run for an hour, I calculate it will take
at least 7 hours to finish reading the file. The file size is 7547 KB as of
right now, but it is constantly growing. I am hoping a bright mind could look
at my code and see if there is something I could do to speed it up. At first
I thought it was my pc because it has been acting up, but I tested it on a
newer pc and have the same difficulty.
Just for info - I need to have the data in every fourth column as I then use
the text to columns function, filter by date in column a - if it meets a
certain criteria, I clear A and shift columns E through IR 4 columns to the
left. At this time, all this is done with other macros and formulas;
eventually I will combine into one, but I am working in pieces for my own
clarity.
Sub Autpen()
MsgBox "Hello"
Columns("a:ir").EntireColumn.Clear
Dim FileName As String
Dim ResultStr As String
Dim FileNum As Integer
Dim Counter As Double
FileName = Application.GetOpenFilename
Application.ScreenUpdating = False
If FileName = "False" Then End
FileNum = FreeFile()
Open FileName For Input As #FileNum
Sheet1.Cells(2, 1).Select
Counter = 1
ColCounter = 4
Do While Seek(FileNum) <= LOF(FileNum)
If EOF(FileNum) Then End
Application.StatusBar = "Reading Row " & Counter & " of text file " &
FileName
Line Input #FileNum, ResultStr
ActiveCell.Value = ResultStr
If ActiveCell.Row = 65536 Then
ColCounter = ColCounter + 1
Sheet1.Cells(2, ColCounter).Select
Else
ActiveCell.Offset(1, 0).Select
End If
Counter = Counter + 1
Loop
Close
Application.ScreenUpdating = True
Application.StatusBar = False
End Sub
I esc to end the macro, and hit the debugger. It stops at this line:
If ActiveCell.Row = 65536 Then
Almost everything in that macro I have found here in this community - thank
you; and thank you in advance for any ideas.
I have a macro that imports a large text file into excel; it puts the data
in every fourth column after column A (starting in A2) fills up); last week
it was running fairly fast - it took maybe 20-30 seconds to read over 70,000
lines. This week, it has slowed down considerably and I didn't make any code
changes. Tonight after letting it run for an hour, I calculate it will take
at least 7 hours to finish reading the file. The file size is 7547 KB as of
right now, but it is constantly growing. I am hoping a bright mind could look
at my code and see if there is something I could do to speed it up. At first
I thought it was my pc because it has been acting up, but I tested it on a
newer pc and have the same difficulty.
Just for info - I need to have the data in every fourth column as I then use
the text to columns function, filter by date in column a - if it meets a
certain criteria, I clear A and shift columns E through IR 4 columns to the
left. At this time, all this is done with other macros and formulas;
eventually I will combine into one, but I am working in pieces for my own
clarity.
Sub Autpen()
MsgBox "Hello"
Columns("a:ir").EntireColumn.Clear
Dim FileName As String
Dim ResultStr As String
Dim FileNum As Integer
Dim Counter As Double
FileName = Application.GetOpenFilename
Application.ScreenUpdating = False
If FileName = "False" Then End
FileNum = FreeFile()
Open FileName For Input As #FileNum
Sheet1.Cells(2, 1).Select
Counter = 1
ColCounter = 4
Do While Seek(FileNum) <= LOF(FileNum)
If EOF(FileNum) Then End
Application.StatusBar = "Reading Row " & Counter & " of text file " &
FileName
Line Input #FileNum, ResultStr
ActiveCell.Value = ResultStr
If ActiveCell.Row = 65536 Then
ColCounter = ColCounter + 1
Sheet1.Cells(2, ColCounter).Select
Else
ActiveCell.Offset(1, 0).Select
End If
Counter = Counter + 1
Loop
Close
Application.ScreenUpdating = True
Application.StatusBar = False
End Sub
I esc to end the macro, and hit the debugger. It stops at this line:
If ActiveCell.Row = 65536 Then
Almost everything in that macro I have found here in this community - thank
you; and thank you in advance for any ideas.