This is code I use to calculate a SI, eg SPI based on hours only
Sub UpdateStatusIndex()
On Error Resume Next
Dim tsv As TimeScaleValue
Dim tsvs As TimeScaleValues
Dim tsvc As TimeScaleValues
Dim TotWork As Single
TotWork = 0
' Update Project Summary Task
'ActiveProject.Tasks(65).TimeScaleData(StartDate:=ActiveProject.ProjectStart, EndDate:=ActiveProject.StatusDate,type:=
Set tsvs =
ActiveProject.ProjectSummaryTask.TimeScaleData(StartDate:=ActiveProject.ProjectStart,
EndDate:=ActiveProject.StatusDate, Type:=pjTaskTimescaledBaselineWork,
TimeScaleUnit:=pjTimescaleDays, Count:=1)
For Each tsv In tsvs
TotWork = TotWork + Val(tsv.Value) / 60
'Debug.Print tsv.StartDate, Val(tsv.Value) / 60
Next tsv
'Debug.Print TotWork, ActiveProject.ProjectSummaryTask.Name
If TotWork > 0 Then
'ActiveProject.ProjectSummaryTask.Number8 =
ActiveProject.ProjectSummaryTask.ActualWork / 60 / TotWork
' ActiveProject.ProjectSummaryTask.SetField
FieldNameToFieldConstant("WTD"), TotWork
ActiveProject.ProjectSummaryTask.SetField FieldNameToFieldConstant("ATD"),
ActiveProject.ProjectSummaryTask.ActualWork / 60
ActiveProject.ProjectSummaryTask.SetField FieldNameToFieldConstant("WTD"),
TotWork
ActiveProject.ProjectSummaryTask.SetField FieldNameToFieldConstant("SI"),
ActiveProject.ProjectSummaryTask.GetField(FieldNameToFieldConstant("ATD")) /
TotWork
End If
TotWork = 0
' Update all tasks
Set objSelection = ActiveProject.Tasks
For Each t In objSelection
Set tsvs = t.TimeScaleData(StartDate:=ActiveProject.ProjectStart,
EndDate:=ActiveProject.StatusDate, Type:=pjTaskTimescaledBaselineWork,
TimeScaleUnit:=pjTimescaleDays, Count:=1)
For Each tsv In tsvs
TotWork = TotWork + Val(tsv.Value) / 60
'Debug.Print tsv.StartDate, Val(tsv.Value) / 60
Next tsv
'Debug.Print TotWork, t.Name, t.ActualStart
If TotWork > 0 Then
't.Number8 = t.ActualWork / 60
t.SetField FieldNameToFieldConstant("ATD"), t.ActualWork / 60
t.SetField FieldNameToFieldConstant("WTD"), TotWork
t.SetField FieldNameToFieldConstant("SI"),
t.GetField(FieldNameToFieldConstant("ATD")) / TotWork
ElseIf (t.BaselineStart < ActiveProject.StatusDate) Then
If (IsDate(t.ActualStart)) Then
t.SetField FieldNameToFieldConstant("SI"), 0
Else
t.SetField FieldNameToFieldConstant("SI"), 10.01
End If
End If
TotWork = 0
Next t
'Debug.Print "done"
End Sub