PRJ: Using DateDifference to Calculate Planned % Complete (137673)



The information in this article applies to:

  • Microsoft Project 98 for Windows
  • Microsoft Project for Windows 95 4.1
  • Microsoft Project for Windows 95 4.1a
  • Microsoft Project for Windows 4.0
  • Microsoft Project for the Macintosh 4.0

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
				

Modification Type:MajorLast Reviewed:11/25/2003
Keywords:kbcode kbhowto kbProgramming KB137673