Hi OTPM,
Try:
Code:
Function RiskTest(Rng1 As Range, Rng2 As Range, Rng3 As Range, Rng4 As Range) As String
Dim LastRow As Long, LastCol As Long, i As Long, j As Long
RiskTest = "On Time"
LastRow = Rng1.Row
LastCol = Rng1.EntireRow.Columns(Rng1.EntireRow.Columns.Count).End(xlToLeft).Column
If Rng1.Value = 0 Then
If Rng3.Rows(LastRow).Value < Rng4.Value Then
RiskTest = "At Risk"
End If
Exit Function
End If
For i = Rng1.Column To LastCol
For j = 1 To LastRow
If Rng1.Columns(i).Value = Rng2.Rows(j).Value Then
If Rng3.Rows(j).Value < Rng4.Value Then
RiskTest = "At Risk"
Exit Function
End If
End If
Next
Next
End Function
The function is now called with four parameters, thus:
=RiskTest($I$11,$A:$A,$F:$F,$F$13)
(the $ constraints are optional), where:
• the 1st parameter is the address of the first predecessor to test
• the 2nd parameter is the column holding the project IDs
• the 3rd parameter is the column holding the project completion dates
• the 4th parameter is the address of the cell holding the completion date against which to test the predecessors.