Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Field Showing Work for a Resource Group

Status
Not open for further replies.

Nora73

Technical User
Sep 4, 2011
2
GR
Hallo again,

I use the following code for calculating the total work of a resource group in a Gantt Chart field.

------------------------------------------------------------------------------------------------------------------------

Public Sub GetCoreWork()
Dim Task As Task
Dim Resource As Resource
Dim CoreWork As Double
Dim Assignment As Assignment

For Each Task In ThisProject.Tasks

If Task.OutlineChildren.Count = 0 Then

With Task

CoreWork = 0

For Each Resource In Task.Resources

For Each Assignment In Task.Assignments

If ThisProject.Resources(Assignment.ResourceName).Group = "Core" Then
CoreWork = Assignment.Work
End If

Next

Task.Number1 = CoreWork / 480

Next

End With

End If

Next

End Sub

------------------------------------------------------------------------------------------------------------------------
Unfortunately, if there is more than one resources assign to a task (of the same resource group) the code writes only the work of one resource, not the sum of the total work of group Core (total work of all persons of group Core, assign to the specific task).

Could you please help me with this ?
Where did i go wrong ?

Thanks in advance again !
Nora
 
I'm not sure I understand your logic.

To me, it appears you are going to each task and then, for each task, you then loop through all resources (not just those assigned to the task).

Try this code instead:

Option Explicit
Public Sub PDQBach()
Dim tsk As Task
Dim res As Resource
Dim asgn As Assignment
Dim intMinsPerDay As Integer
Dim dblCoreWork As Double

intMinsPerDay = ActiveProject.HoursPerDay * 60

For Each tsk In ActiveProject.Tasks
If Not tsk Is Nothing Then
If Not tsk.Summary Then
dblCoreWork = 0
For Each asgn In tsk.Assignments
If UCase(asgn.Resource.Group) = "CORE" Then
dblCoreWork = dblCoreWork + asgn.Work
End If
Next
tsk.Number1 = dblCoreWork / intMinsPerDay
End If
End If
Next
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top