nickshep85
New Member
- Joined
- Mar 21, 2012
- Messages
- 37
I have the below code as part of a macro, which I use to import rows of data from one workbook and put them into one of three tabs. This used to import into two tabs until the number of rows increased, so I'm assuming that one of the changes I have made is causing this code to run slowly.
The bold code is the part that I have added in recently.
Can someone please help me figure out what is causing this code to run so slowly. I used to be able to import and sort 70,000 rows in 10 minutes, but I had to force break this code after an hour.
The bold code is the part that I have added in recently.
Can someone please help me figure out what is causing this code to run so slowly. I used to be able to import and sort 70,000 rows in 10 minutes, but I had to force break this code after an hour.
Code:
Workbooks("PriceFile.xls").Activate
m = 3
n = 3
t = 3
For i = 1 To Workbooks("PriceFile.xls").Sheets.Count
Worksheets(i).Select
Range("A1").Select
Selection.End(xlDown).Select
End_Row = ActiveCell.Row
l = 1
Do Until l = End_Row
[B]
If Workbooks("Importfile.xls").Worksheets("Mechanical").UsedRange.Rows.Count > 65534 Then
If Cells(i, 9).Value = "True" Then
Rows(l).Copy
Workbooks("ImportFile.xls").Activate
Worksheets("Mechanical2").Select
Cells(m, 1).Select
ActiveSheet.Paste
m = m + 1
End If
Else
' ^^^ Used to be End If[/B]
If Cells(l, 9).Value = "True" Then
Rows(l).Copy
Workbooks("ImportFile.xls").Activate
Worksheets("Mechanical").Select
Cells(n, 1).Select
ActiveSheet.Paste
n = n + 1
End If
If Cells(l, 9).Value = "False" Then
Rows(l).Copy
Workbooks("ImportFile.xls").Activate
Worksheets("Tyres").Select
Cells(t, 1).Select
ActiveSheet.Paste
t = t + 1
End If
Workbooks("PriceFile.xls").Activate
Worksheets(i).Select
l = l + 1
End If
Loop
Next i