Knowledge Base

PRJ: Using DateDifference to Calculate Planned % Complete

Article ID: 137673

Article Last Modified on 1/19/2007


APPLIES TO


This article was previously published under Q137673

SUMMARY

The Microsoft Project Visual Basic for applications DateDifference, DateAdd, and DateSubract methods provide ways for you to create custom date calculations that take into consideration your project calendars.

MORE INFORMATION

The following macro uses the DateDifference method to calculate a task's planned percent complete based on working time. A task's planned percent complete can be used for custom earned value calculations.

Microsoft provides examples of Visual Basic for applications procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose.
Sub Planned_Percent_Complete()
   'Get the current date.
   dCurrentDate = ActiveProject.CurrentDate
   'Loop through each task in the project
   For Each ATask In ActiveProject.Tasks
      PlPctComp = 0
      'skip blank rows
      If Not ATask Is Nothing Then
      'Check for Baseline Start and Baseline Finish
         If (IsDate(ATask.BaselineStart) And _
            IsDate(ATask.BaselineFinish)) Then
            'Zero duration tasks
            If dCurrentDate >= ATask.BaselineFinish Then
               PlPctComp = "100%"
            Else
               vTemp = Application.DateDifference(ATask.BaselineStart, _
                       ATask.BaselineFinish)
               If vTemp = 0 Then
                  PlPctComp = "0%"
               Else
                  PlPctComp = 		     
Format(Application.DateDifference(ATask.BaselineStart, _
                   dCurrentDate) / vTemp, "0%")
               End If
            End If
            ATask.Text1 = PlPctComp
         Else
            'No baseline start/finish, set to NA
            ATask.Text1 = "NA"
         End If
       End If
   Next ATask
End Sub
				

Additional query words: attached function BCWS

Keywords: kbcode kbhowto kbprogramming KB137673