VBA - Deleting Tasks (criteria based)

R
Rob Garbutt 👤 Member for 8 years 10 months

Hi all, I'm looking for some help using VBA to delete rows in an MSP I own. There aretasks in my plan labelled as either "C" or "I" (as in Client or Internal) using a custom "text23" column. I'm currently having to manually delete, line by line those labelled "I" in order to send my client a sanitised version of the plan.

 

I'm not quite at the stage yet to write my own VBA, but I'm certainly able to administer it. does anyone have an idea as to how the code to perform this task should look?

R
Rob Garbutt 👤 Member for 8 years 10 months

Thanks Tom, this is really useful.  Strangely I appear to have to run the macro a couple of times in order to delete all "I" tasks, but it beats doing it manually that's for sure! (my plan is 5k tasks long).

Also I agree with your advice regarding this method being slightly risky, and in all honesty I don't see any reason to hide anything from the client anyway, but I aint the boss!  Ultimately I'm untertaking this task manually regardless, so I've ensured that no logic will be broken in the process, and now it's automated it can be done much quicker!

Thanks again,

Rob

T
Tom Boyle 👤 Member for 19 years 6 months

Hi Rob,

Here's a simple procedure that does what you suggest for a simple project I tested it on.

Sub DeleteInternal()

Dim t As Task

    For Each t In ActiveProject.Tasks

        If Not t Is Nothing Then

            If t.Text23 = "I" Then t.Delete

        End If

    Next t

End Sub

 

 

 
Personally I would never use this kind of hammer on one of my schedules - without very serious review and confirmation of the "I" codes.  You are liable to break some logical or resource link, and the client will not be happy when they open your schedule, calculate it, and get different results than you have.
 
You might also consider developing a routine that simply obfuscates the names of the tasks, leaving the logic and other data untouched.
 
Good luck, tom

Forum Sponsor

Top Posters

Julian Pegg
1 posts
Peter Nagy
2 posts
Raymund de Laza
17 posts
Syed_Asad
0 posts
Tony Greyvenstein
0 posts
Ahmed Al-Jubouri
13 posts
Umar Alvi
3 posts
Sibusiso Mahlalela
0 posts
Michael Samanyayi
3 posts
Simon Gumede
0 posts