2
votes

Sorry if this is an easy question, I just started using vba with MS Project.

I am trying to cycle through all the tasks in a MS Project file and delete a task if it meets a certain criteria. The problem happens after a task is deleted, it seems like the j task variable gets set to Nothing, which screws everything up. Any idea how I can do this?

For Each j In prj.Tasks

    If j.Text10 = "1" Or j.Text10 = "2" Then ' If criteria is met

        SelectRow Row:=j ' Select the row
        EditDelete        ' Delete the row

    End If
Next j
1
use a for x = maxTasks to 1 step -1 that way your counter doesn't lose it's placeSorceri

1 Answers

1
votes

this is how I have done it in the past, check through all tasks in the project.

I'm not 100% sure on the syntax as it's been a while since I've worked with project and i copied this from vb.net

Dim T as Task

For Each T In Application.Tasks
    If T.Text10 = "1" Or T.Text10 = "2" Then
        T.Delete
    End If
Next

after looking at your code again it looks like you just need to change

.... Then
    j.Delete
End if