PRJ: Using DateDifference to Calculate Planned % Complete

Last reviewed: November 24, 1997
Article ID: Q137673
The information in this article applies to:
  • Microsoft Project 98 for Windows
  • Microsoft Project for Windows 95, versions 4.1, 4.1a
  • Microsoft Project for Windows, version 4.0
  • Microsoft Project for the Macintosh, version 4.0

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: 4.00 4.10 attached function BCWS
Keywords : kbcode kbprg
Version : 4.0 4.1 4.1a 98
Platform : MACINTOSH WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 24, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.