THRASHER69
Board Regular
- Joined
- Mar 29, 2012
- Messages
- 200
Hello,
I'm hoping someone here can tell me if there is a way to write the below code that would make it run faster. It is really slowing down things. I know it is doing a lot but it's taking 10 around 10 minutes just for this part of the code. Any help would be much appreciated. I highlighted the section of code I am having issues with in red:
I'm hoping someone here can tell me if there is a way to write the below code that would make it run faster. It is really slowing down things. I know it is doing a lot but it's taking 10 around 10 minutes just for this part of the code. Any help would be much appreciated. I highlighted the section of code I am having issues with in red:
Code:
lr = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row + 1
TRow = "Conf. Date"
Cells.Find(what:=TRow).Activate
TRow = ActiveCell.Row
For i = lr To TRow Step -1
AItem = Cells(i - 1, 1).Address
EItem = Cells(i - 1, 5).Address
RCnt = Application.Evaluate("SumProduct(--(A:A=" & AItem & "),--(E:E=" & EItem & "))")
If i - RCnt < TRow Then GoTo 0
If i = lr Then
x = Cells(i - RCnt, "I").Address
y = Cells(i - 1, "I").Address
Cells(i, "I").Formula = "=SUBTOTAL(9," & x & ":" & y & ")"
Cells(i - 1, "I").Copy
Cells(lr, "I").PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
End If
[COLOR=#ff0000] If Cells(i, "E") <> Cells(i - 1, "E") And i <> lr Then[/COLOR]
[COLOR=#ff0000] Rows(i).Resize(2).EntireRow.Insert[/COLOR]
[COLOR=#ff0000] Range(Cells(TRow, "A"), Cells(TRow, "J")).Copy Destination:=Range("A" & i + 1)[/COLOR]
[COLOR=#ff0000] x = Cells(i - RCnt, "I").Address[/COLOR]
[COLOR=#ff0000] y = Cells(i - 1, "I").Address[/COLOR]
[COLOR=#ff0000] Cells(i, "I").Formula = "=SUBTOTAL(9," & x & ":" & y & ")"[/COLOR]
[COLOR=#ff0000] Cells(i, "I").Font.Bold = True[/COLOR]
[COLOR=#ff0000] Cells(i, "I").Font.Size = 12[/COLOR]
[COLOR=#ff0000] Cells(i, "I").Font.Color = RGB(255, 0, 0)[/COLOR]
[COLOR=#ff0000] End If[/COLOR]
Next i