Link to last task

J

John

I am trying to find the latest finish date for a group of tasks assigned to
a certain resource and then to link that task to another one as a
predecessor. I got it to work with the following code. Is there an easier
and quicker way to do this?

- John


Sub Last_Task_Link()

'If project is empty, alert the user and end the macro
If ActiveProject.Tasks.Count = 0 Then
MsgBox MSG_NO_TASKS, Buttons:=vbCritical + R_TO_L,
Title:=Application.Name
End
End If


Dim Temp As Long, Temp2 As Long
Dim R As Long, Names As String, FinishDate As Date, FinishID As String

For R = 1 To ActiveProject.Resources.Count
FinishID = 0
FinishDate = 0
Names = ActiveProject.Resources(R).Name
For Temp = 1 To ActiveProject.Tasks.Count
If Not ActiveProject.Tasks(Temp) Is Nothing Then
If StrComp(Names, ActiveProject.Tasks(Temp).ResourceNames, 1) =
0 Then
If DateValue(ActiveProject.Tasks(Temp).Finish) >=
DateValue(FinishDate) Then
FinishDate = ActiveProject.Tasks(Temp).Finish
FinishID = ActiveProject.Tasks(Temp).ID
End If
End If
End If
Next Temp
For Temp2 = 1 To ActiveProject.Tasks.Count
If Not ActiveProject.Tasks(Temp2) Is Nothing Then
If StrComp(Names, ActiveProject.Tasks(Temp2).Name, 1) = 0 Then
If Not FinishID = 0 Then
ActiveProject.Tasks(Temp2).Predecessors = FinishID
End If
End If
End If
Next Temp2
Next R

End Sub
 
J

Jan De Messemaeker

Hi John,

Not really I thion. One can imagine more concise ways to write some of the
stuff, but essentially this is sound logic.
HTH
 

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