我正在编写VBA代码以根据某些条件自动更新记分卡表。 如果日期已过今天并且要求状态,则设置为绿色 如果日期已过今天并且状态为其他,则设置为灰色 如果日期早于今天,则设置为红色
已经尝试运行条件式if,代码如下所示。尽管下面的代码中都包含了“ p> Next Without For”,但不断出现编译错误,提示“
Dim i As Integer
For i = 7 to Last_Row
If Cells(i,Phase).Value = "3" Then
If Cells(i,PSEDate).Value > Date Then
If Cells(i,P3S).Value = "Requested" Then
Cells(i,RAG).Value = "Green"
Else
Cells(i,RAG).Value = "Gray"
End If
Else
Cells(i,RAG).Value = "Red"
End if
Next i
答案 0 :(得分:0)
您在这里还缺少一个null
子句:
Else...End If
答案 1 :(得分:0)
如BigBen所述,您缺少一个“ End If”语句。还要尝试使用缩进来发现此类错误。
Dim i As Integer
With Sheet1
For i = 7 To 17
'First condition
If .Cells(i, 1).Value = "3" Then
'Second condition
If .Cells(i, 2).Value > Date Then
'Third condition
If .Cells(i, 3).Value = "Requested" Then
.Cells(i, 4).Value = "Green"
Else
.Cells(i, 4).Value = "Gray"
'Third condition end
End If
Else
.Cells(i, 4).Value = "Red"
'Second condition end
End If
'First condition end
End If
Next i
End With