1

How can I show the main (resource with maximum hours) for Summary tasks. I suspect I would need to set a custom text field to show this, but how would I structure this? thanks

0

The below function does what I was after.

Public Sub showMainResource()

    Dim i As Long, j As Long

    Dim tsk As Task
    Dim rsc As Resource
    Dim ass As Assignment

    Dim dataArr() As Double
    Dim dataArrCount As Long
    dataArrCount = -1

    Dim resourceCount As Long
    resourceCount = ActiveProject.Resources.Count

    Dim taskCount As Long
    taskCount = ActiveProject.Tasks.Count

    ReDim dataArr(taskCount, resourceCount)

    Dim iMax As Long
    Dim iID As Long

    'walk the tasks backwards
    For i = taskCount To 1 Step -1
        Set tsk = ActiveProject.Tasks.Item(i)

        'loop through resource assignments and add hours
        For Each ass In tsk.Assignments
            'log the value
            dataArr(tsk.ID, ass.Resource.ID) = dataArr(tsk.ID, ass.Resource.ID) + ass.Work
        Next ass

        'add the values to the parent
        For j = 1 To resourceCount
            'log the value to its parent as well
            dataArr(tsk.OutlineParent.ID, j) = dataArr(tsk.OutlineParent.ID, j) + dataArr(tsk.ID, j)
        Next j

        'code to do something with the results,
        'below takes the resource with highest work and shows it in Text2 for Summary tasks only
        If tsk.Summary Then
            iMax = 0
            iID = 0
            For j = 1 To resourceCount
                'find the reource with max work
                If dataArr(tsk.ID, j) > iMax Then
                    iMax = dataArr(tsk.ID, j)
                    iID = j
                End If
            Next j
            If iID > 0 Then
                'write the value
                tsk.Text2 = ActiveProject.Resources.Item(iID).Name
            Else
                tsk.Text2 = vbNullString
            End If
        End If
    Next i
End Sub

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.