I have an operation that takes too long. Please suggest how to make it run faster.
Thanks,
Lenna
Code:
Option Compare Text
Sub Takes2Long()
Application.ScreenUpdating = False
Dim cel As Range, rng As Range, lr As Long
Dim cel1 As Range, rng1 As Range, lr1 As Long
'deletecellsunderneath
lr = Worksheets("Sheet1 (2)").Cells(Rows.Count, "Q").End(xlUp).Row
Set rng = Worksheets("Sheet1 (2)").Range("Q2:Q" & lr) 'assumes a header row
For Each cel In rng
If InStr(cel.Value, "donor") > 0 Or InStr(cel.Value, "transplant") > 0 Then
lr2 = Worksheets("DSA").Cells(Rows.Count, "Q").End(xlUp).Row 'sheet being pasted to, change if needed
cel.Offset(1, 0).EntireRow.Cut Destination:=Worksheets("DSA").Range("A" & lr2 + 1)
End If
Next cel
'cutdonorandtrasnplant
lr1 = Worksheets("Sheet1 (2)").Cells(Rows.Count, "Q").End(xlUp).Row
Set rng1 = Worksheets("Sheet1 (2)").Range("Q2:Q" & lr1) 'assumes a header row
For Each cel1 In rng1
If InStr(cel1.Value, "donor") > 0 Or InStr(cel1.Value, "transplant") > 0 Then
lr3 = Worksheets("DSA").Cells(Rows.Count, "Q").End(xlUp).Row 'sheet being pasted to, change if needed
cel1.Offset(0, 0).EntireRow.Cut Destination:=Worksheets("DSA").Range("A" & lr3 + 1)
End If
Next cel1
Application.ScreenUpdating = True
End Sub
Lenna