Re: Keep Task Days Together
- From: John <mjensen@xxxxxxxxxxxx>
- Date: Wed, 28 Dec 2005 15:37:57 -0700
In article <63117EFB-FC48-4930-8F81-CFD668F9492C@xxxxxxxxxxxxx>,
"MSPuser" <MSPuser@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> John,
>
> Thank you very much again for pointing me in the right direction and for
> providing valuable code.
> I tried it and had to modify it for a real schedule for the following
> reasons:
>
> 1. It would move ALL the tasks, even those that use the Standard calendar,
> as long as they start before the Restart date and have Start+Duration >
> Cutoff date. To avoid that I modyfied the IF statement to check for
> t.Calendar = "SpringAndFall".
>
> 2. The code you wrote puts the â??Start Not Earlier Thanâ?? constraints in
> order to move the tasks. Next time the schedule is adjusted backward (if
> construction finished earlier), the tasks would not move back because of the
> constraints. To avoid that I put a loop that removes all previously placed
> constraints before re-applying them.
>
> Please see the code below. I would appreciate your comments.
> --------------------------------------------
> Sub Schedule_Gapper2()
> Dim Cutoff As Date, Restart As Date
> Dim t As Object
>
> 'First remove all previously created constraints
> For Each t In ActiveProject.Tasks
> If Not t Is Nothing Then
> Restart = "9/1/" & Year(t.Start)
> If t.Summary = False And t.Calendar = "SpringAndFall" Then
> If t.ConstraintDate = Restart And t.ConstraintType = pjSNET
> Then
> t.ConstraintType = pjASAP
> End If
> End If
> End If
> Next t
>
> â??Reapply Constraints
> For Each t In ActiveProject.Tasks
> If Not t Is Nothing Then
> Cutoff = "5/31/" & Year(t.Start)
> Restart = "9/1/" & Year(t.Start)
>
> â??Removed as it moves regular tasks also
> 'If t.Summary = False And t.Start < Restart Then
> 'If Application.DateAdd(t.Start, t.Duration) > _
> 'Cutoff Then t.Start = Restart
> 'End If
>
> If t.Summary = False And t.Calendar = "SpringAndFall" Then
> If t.Start <= Cutoff And t.Finish >= Restart Then
> t.Start = Restart
> End If
> End If
> End If
> Next t
> End Sub
> ------------------------------------------------------------------------------
> ---------
> MSPuser
MSPuser,
My simple macro was based on the limited information you provided and
there certainly is nothing wrong with modifying the code to meet your
needs. I'm glad to see you "picked up the ball and ran with it".
Some comments on your modified code. First, the two loops could be
combined - no need to go through the tasks twice. As long as calculation
is set to automatic, the task will "snap" back based on its predecessor
as soon as the constraint is lifted. The next line of code can set a new
start date if appropriate. Second, the variable "Restart" is defined
twice - it only needs to be defined once as long as the value is not
being changed. But then this becomes mute if the two loops are combined.
Third, the first loop assumes that all tasks with a
"start-no-earlier-than" constraint were set by a previous run of the
macro - that may not always be the case (i.e. some tasks in a project
may not have a valid predecessor and therefore will have their own
independent start date, and most likely, a SNET constraint to go with
it). You might want to set a flag field to separate the two types of
tasks - flag is true if the SNET constraint was set as a result of
running the macro.
Hope this helps.
John
Project MVP
.
- References:
- Re: Keep Task Days Together
- From: John
- Re: Keep Task Days Together
- From: MSPuser
- Re: Keep Task Days Together
- From: John
- Re: Keep Task Days Together
- From: MSPuser
- Re: Keep Task Days Together
- Prev by Date: Re: vertical bars in gantt view (MS Project)
- Next by Date: Re: vertical bars in gantt view (MS Project)
- Previous by thread: Re: Keep Task Days Together
- Next by thread: Re: Finish Date does not change
- Index(es):
Relevant Pages
|