macro to count all tasks (no sumary or milestones) in a project

J

JulieS

I'm sure you meant to give us more details, Manny. As a suggestion:
What version of Project?
Project stand alone or with server?
Why do you wish to count the number of non-summary, non-milestone tasks?
What are you trying to accomplish -- perhaps there is a better answer we
can suggestion.


Julie
Project MVP

Visit http://project.mvps.org/ for the FAQs and additional
information about Microsoft Project
 
J

Jack Dahlgren MVP

sub countTheTasks()
dim I as integer
I = 0
for each task in activeproject.tasks
if not task is nothing then
if not task.summary then
I - I + 1
end if
end if
next task
msgbox "this project contains " & I & " tasks"
end sub
 
J

John4bank

Here is a task counter that I had created a while ago


Sub Task_Counter()

ViewApply Name:="&Gantt Chart" 'macro must be run from the Gantt Chart view

AllTasks = 0
SubTasks = 0
y = 101
Comp = 0
Uncomp = 0
Unstarted = 0
Dim t As Task
Dim ts As Tasks
Set ts = ActiveProject.Tasks
For Each t In ts
If Not t Is Nothing Then 'avoid all blank tasks
AllTasks = AllTasks + 1 'count all tasks including summary tasks
If Not t.Summary Then 'skip summary tasks
SubTasks = SubTasks + 1 ' count subtasks tasks
y = t.PercentComplete
If y = 100 Then
Comp = Comp + 1 'count completed tasks
End If
If y < 100 And y > 0 Then
Uncomp = Uncomp + 1 'count started, but not completed tasks
End If
If y = 0 Then
Unstarted = Unstarted + 1 'count tasks that haven't started
yet
End If
End If
End If
Next t
'display the results of the counters
MsgBox "There are " + Str(AllTasks) + " total tasks, " + Str(SubTasks) + "
subtasks, " + Str(Comp) + " completed tasks, " + Str(Uncomp) + " tasks that
are partially completed, and " + Str(Unstarted) + " tasks that haven't been
started."
End Sub
 
E

Elvis

This is a great way to count all tasks but I have found that most often the
data I want to analyze in excel is the product of different views and only
the tasks associated with those views. How would this count procudure look
if it were counting just tasks in the CurrentView?
 
J

Jim Aksel

Two more things to throw into the mix...
Off the top of my head, you can create a view and then select all the tasks
in the view (a filtered view for instance). Then in Jack or John4's code,
you could replace the for each with this:

Dim t As Task
For Each t In Application.ActiveSelection.Tasks



One other thing to think of, if the file is a master project with external
predecessors or successors, then there is one more nest on the "IF" statement

Dim t as task
if not t.ExternalTask=true then ...

or
if t.externaltask = false then
--
If this post was helpful, please consider rating it.

Jim Aksel, MVP

Check out my blog for more information:
http://www.msprojectblog.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top