Hi all,

I have a workbook with one sheet (called "Pipeline") and another sheet called "Completed". The Pipeline sheet is used to keep track of all of the tasks that the team are working on, and then when the task is completed, it needs to be moved to the "Completed tab".

I currently have managed to write some code that looks for items marked "completed" in row G of the "Pipeline" sheet, then copies them over to the "Completed" tab, and then deletes the row from the "Pipeline" sheet.

There is one macro to copy the completed cells (called "Transfer"), and then another to delete the cells (called "Delete"). I then just have macro called "Clean" that just calls the transfer macro, and then calls the delete macro.

However, I'm new to VBA and I'm pretty sure the code is awful as it sometimes just doesn't work. Often, there are 6 tasks marked complete, and only some of them will be copied over, but all of them will be deleted (a disaster).

I'm just hoping if anyone could give me some tips to make the code better and more robust? Thanks!

Transfer Macro:

Sub Transfer()

Application.EnableEvents = False

Set wbk = ActiveWorkbook

wbk.Worksheets("Pipeline").Activate
wbk.Worksheets("Pipeline").Range("B5").Select

For x = 5 To 180

    If Worksheets("Pipeline").Cells(x, 7) = "Completed" Then
        wbk.Worksheets("Pipeline").Activate
        wbk.Worksheets("Pipeline").Range(Cells(x, 2), Cells(x, 27)).Copy
        wbk.Worksheets("Completed").Activate
        wbk.Worksheets("Completed").Range("g5").End(xlDown).Offset(1, -5).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
        
        Application.CutCopyMode = False
             
        
    Else:

    End If

Next

wbk.Worksheets("Pipeline").Activate
wbk.Worksheets("Pipeline").Range("B5").Select

Application.EnableEvents = True

End Sub
Delete Macro:


Sub Delete()

Application.EnableEvents = False
    
    For J = 5 To 7

        If Cells(J, 7) = "Completed" Then

            Worksheets("Pipeline").Range(Cells(J, 2), Cells(J, 27)).Delete
        Else:
        
        End If

    Next

    For t = 5 To 180
            If Cells(t, 7) = "Completed" Then

            Worksheets("Pipeline").Range(Cells(t, 2), Cells(t, 27)).Delete
        Else:
        
        End If

    Next
    
      For q = 5 To 180
            If Cells(q, 7) = "Completed" Then

            Worksheets("Pipeline").Range(Cells(q, 2), Cells(q, 27)).Delete
        Else:
        
        End If

    Next
    
Application.EnableEvents = True

End Sub
Overall Macro:

Sub clean()

Call Transfer

Call Delete

End Sub