Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

36 views
Skip to first unread message

Marty

unread,
Feb 8, 2010, 1:55:01 PM2/8/10
to

JulieS

unread,
Feb 8, 2010, 2:12:13 PM2/8/10
to

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

On 2/8/2010 1:55 PM, Marty wrote:
>

Jack Dahlgren MVP

unread,
Feb 8, 2010, 7:08:54 PM2/8/10
to
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

"Marty" <Ma...@discussions.microsoft.com> wrote in message
news:6AF55171-A29E-4285...@microsoft.com...
>

John4bank

unread,
Feb 9, 2010, 2:28:12 PM2/9/10
to
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

"Jack Dahlgren MVP" wrote:

> .
>

Elvis

unread,
Feb 9, 2010, 10:49:01 PM2/9/10
to
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?


"Jack Dahlgren MVP" wrote:

> .
>

Jim Aksel

unread,
Feb 10, 2010, 12:56:02 AM2/10/10
to
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

0 new messages