I am trying to loop through all tasks, check them against a condition and then delete the ones that match the condition. The problem I am having is that the foreach loop exists after I delete the first task. In the code below I am trying to identify whether the task matches one in a variant array (imported from excel)

For Each Task In ActiveProject.Tasks
            
            If Task.Text10 = "Work Order" Then
                FoundWO = False
                For j = LBound(vData) To UBound(vData)
                    If vData(j, 2) = Task.Text3 Then 'Found the work order header, dont delete it
                        FoundWO = True
                        Exit For
                    End If
                Next j
                If FoundWO = False Then
                    Task.Delete
                End If
            End If
        Next Task
The loop will work fine UNTIL I delete the first task. After the delete it exits at the "Next Task" line.

Can anyone help me understand why this is happening?