I was reading about similar problems to the one I am having, and my guess is that I am having a 'memory leak'. I'm not sure exactly what that means, or how to correct it. Could you take a look at my code and help me optimize? LastRow in this bit is a little over 70000.
start = Timer
For Row = 4 To LastRow
DoEvents
If Original.Cells(Row, 4) <> "" Then
Application.StatusBar = "Progress: " & Row & " out of " & LastRow & ": " & Format(Row / LastRow, "0.00%")
'VLookUp method
''''' Data.Cells(DataRow, 1).value = Original.Cells(Row, 4).value
''''' Data.Cells(DataRow, 2).value = Original.Cells(Row, 39).value
''''' Result = Evaluate("Vlookup('New Cost Data'!A" & DataRow & ",'PupFile Data'!B:D,3,false)")
'''''
''''' If IsError(Result) = True Then
''''' Data.Cells(DataRow, 3) = "No Old Cost"
''''' DataRow = DataRow + 1
''''' ElseIf Result = 0 Then
''''' Data.Cells(DataRow, 3) = "No Old Cost"
''''' DataRow = DataRow + 1
''''' Else
''''' Data.Cells(DataRow, 3) = Result
''''' Data.Cells(DataRow, 4) = Format((Data.Cells(DataRow, 2) - Result) / Result, "0.00%")
''''' DataRow = DataRow + 1
''''' End If
'Find() method
Set RNGFound = Range(Pup.Cells(2, 2), Pup.Cells(Pup.Cells(Rows.count, 2).End(xlUp).Row, 2)).Find(Original.Cells(Row, 4))
If Not RNGFound Is Nothing Then
PupRow = Range(Pup.Cells(2, 2), Pup.Cells(Pup.Cells(Rows.count, 2).End(xlUp).Row, 2)).Find(Original.Cells(Row, 4), lookat:=xlWhole, searchorder:=xlRows, MatchCase:=True).Row
Data.Cells(DataRow, 1).Value = Original.Cells(Row, 4).Value
Data.Cells(DataRow, 2).Value = Original.Cells(Row, 39).Value
Data.Cells(DataRow, 3).Value = Pup.Cells(PupRow, 4).Value
Data.Cells(DataRow, 4) = (Data.Cells(DataRow, 2) - Data.Cells(DataRow, 3)) / Data.Cells(DataRow, 3)
Else
Data.Cells(DataRow, 1).Value = Original.Cells(Row, 4).Value
Data.Cells(DataRow, 2).Value = Original.Cells(Row, 39).Value
Data.Cells(DataRow, 3) = "No old Cost"
End If
DataRow = DataRow + 1
End If
Next Row
Application.StatusBar = False
finish = Timer - start
MsgBox finish
Stop
The Vlookup() method took me about 500 seconds, but it slowed down considerably from the beginning. The find() method looked like it was taking much longer, so I am probably going with the vlookup, but what about the actual slowing down of the code? Is there something I need to change, or is slowing down over time just 'what happens'?
vlookupis slowing down because Excel will recalculate the entire sheet each time the formula is entered into a new cell. Setting the calculation to xlManual prior to filling in the formulas should help. Just don't forget to turn it back to automatic after it's done, or it will never get calculated. \$\endgroup\$