Hi,
Can anyone please help me optimize the below code? I need it to run faster by selecting multiple rows at once on sheet "Pipe List" based on the criteria in C2 on sheet "pipeline details" and copying them all over together to sheet "Pipeline Details". Right now my code copies them individually and it is taking too long to run. I am open to completely rewriting this macro.
Sub BranchSort()
Application.ScreenUpdating = False
Call OptimizeCode_Begin
Range("A8:T8").Select
Selection.AutoFilter
Range("A9:T50000").Select
Selection.ClearContents
Dim c As Range
Dim j As Integer
Dim Source As Worksheet
Dim Target As Worksheet
Dim Condition As Worksheet
Set Source = ActiveWorkbook.Worksheets("pipe list")
Set Target = ActiveWorkbook.Worksheets("Pipeline Details")
Set Condition = ActiveWorkbook.Worksheets("Pipeline Details")
j = 9 'This will start copying data to Target sheet at row 9
For Each d In Condition.Range("C2")
For Each c In Source.Range("c2:c50000")
If d = c Then
Source.Rows(c.Row).Copy Target.Rows(j)
j = j + 1
End If
Next c
Next d
Range("C2").Select
Call OptimizeCode_End
Application.ScreenUpdating = True
End Sub
Can anyone please help me optimize the below code? I need it to run faster by selecting multiple rows at once on sheet "Pipe List" based on the criteria in C2 on sheet "pipeline details" and copying them all over together to sheet "Pipeline Details". Right now my code copies them individually and it is taking too long to run. I am open to completely rewriting this macro.
Sub BranchSort()
Application.ScreenUpdating = False
Call OptimizeCode_Begin
Range("A8:T8").Select
Selection.AutoFilter
Range("A9:T50000").Select
Selection.ClearContents
Dim c As Range
Dim j As Integer
Dim Source As Worksheet
Dim Target As Worksheet
Dim Condition As Worksheet
Set Source = ActiveWorkbook.Worksheets("pipe list")
Set Target = ActiveWorkbook.Worksheets("Pipeline Details")
Set Condition = ActiveWorkbook.Worksheets("Pipeline Details")
j = 9 'This will start copying data to Target sheet at row 9
For Each d In Condition.Range("C2")
For Each c In Source.Range("c2:c50000")
If d = c Then
Source.Rows(c.Row).Copy Target.Rows(j)
j = j + 1
End If
Next c
Next d
Range("C2").Select
Call OptimizeCode_End
Application.ScreenUpdating = True
End Sub