I can't tell what you're trying to do. Maybe this:
Sub Calculate_phase()
Dim i As Long 'variable for looping in the for loop
Dim w As Long
w = 8
For i = w To 1 Step -1
Application.Goto ActiveWorkbook.Sheets("Sheet1").Range("P2")
If ActiveCell.Offset(i - 1, 2) <> "" Then
If DateValue(ActiveCell.Offset(i - 1, 2)) < Date Then
ActiveCell.Offset(i - 1, -7).Value = "4"
End If
ElseIf ActiveCell.Offset(i - 1, 1) <> "" Then
If DateValue(ActiveCell.Offset(i - 1, 1)) < Date Then
ActiveCell.Offset(i - 1, -7).Value = "3"
End If
ElseIf ActiveCell.Offset(i - 1, 0) <> "" Then
If DateValue(ActiveCell.Offset(i - 1, 0)) < Date Then
ActiveCell.Offset(i - 1, -7).Value = "2"
Else
ActiveCell.Offset(i - 1, -7).Value = "1"
End If
End If
Next i
End Sub
Also, if the cells in question contain actual dates (as opposed to text that looks like dates), I'd change the coode to look more like this:
Sub Calculate_phase()
Dim i As Long
Dim w As Long
w = 8
For i = w To 1 Step -1
Application.Goto ActiveWorkbook.Sheets("Sheet1").Range("P2")
With ActiveCell
If .Offset(i - 1, 2).Value <> "" Then
If .Offset(i - 1, 2).Value < Date Then
.Offset(i - 1, -7).Value = "4"
End If
ElseIf .Offset(i - 1, 1).Value <> "" Then
If .Offset(i - 1, 1).Value < Date Then
.Offset(i - 1, -7).Value = "3"
End If
ElseIf .Offset(i - 1, 0).Value <> "" Then
If .Offset(i - 1, 0).Value < Date Then
.Offset(i - 1, -7).Value = "2"
Else
.Offset(i - 1, -7).Value = "1"
End If
End If
End With
Next i
End Sub
Bookmarks