2

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 place Commented Feb 15, 2017 at 22:04

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

2 Comments

That was it. Thank you
if that answer worked for you could please accept it as the answer, it helps others who have similar questions to find a working solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.