Thursday, May 5, 2011

How to Roll-up the cost at the summary task level

Sub Test()
Dim cst1 As Integer
Dim cst As Integer
Dim t, t1 As Task
Dim OutlineLevel As Integer
cst1 = 0
OutlineLevel = 1

While OutlineLevel < 15
For Each t In ActiveProject.Tasks
If Not (t Is Nothing) Then
If (t.OutlineLevel = OutlineLevel And t.Summary = True) Then
For Each t1 In t.OutlineChildren
cst = t1.Cost1
cst1 = cst + cst1
Next t1
t.Cost1 = cst1
cst1 = 0
End If
End If
Next t
OutlineLevel = OutlineLevel + 1
Wend
End Sub