我使用的代码包含多个If
条件的And
条件。
此代码正常工作,直到我没有使用多个And
条件,但当我使用多个And
条件时出现错误:
子或功能未定义。
即。当我将代码扩展到下一级作为代码行
时代码如下: -
Sub main()
With Worksheets("Employee Data")
Sheets("Employee Data").Range("AQ4:AQ2000").Value = ""
If Range("F4") = "" Then
Range("AQ4") = ""
Else
If Range("F4").Value = "E1" And Range("AB4").Value = "Yes" Then
Range("AQ4").Formula = "=""Due for Promotion to E2A Level w.e.f."" & TEXT(DATE(YEAR(AP4)+1,MONTH(AP4),DAY(AP4)),""DD-MMM-YYYY"")"
Else
If Range("F4") = "E1" And Range("AB4").Value = "No" Then
Range("AQ4").Formula = "=""Due for Promotion to E2A Level w.e.f."" & TEXT(DATE(YEAR(AP4)+2,MONTH(AP4),DAY(AP4)),""DD-MMM-YYYY"")"
If Range("F4") = "E2" And Range("AB4").Value = "Yes" Then
Range("AQ4").Formula = "=""Due for Promotion to E2A Level w.e.f."" & TEXT(DATE(YEAR(AP4)+1,MONTH(AP4),DAY(AP4)),""DD-MMM-YYYY"")"
Else
If Range("F4") = "E2A" And Range("AB4").Value = "Yes" Then
Range("AQ4").Formula = "=""Due for Promotion to E3 Level w.e.f."" & TEXT(DATE(YEAR(AP4)+4,MONTH(AP4),DAY(AP4)),""DD-MMM-YYYY"")"
' error lies in this code line i.e. sub or function not defined
Else
If Range("F4") = "E2A" And Range("AB4").Value = "NO" And Ragne("P4").Value < 9 And Range("AE4").Value = "NA" Then
Range("AQ4").Formula = "=""Due for Promotion to E3 Level w.e.f."" & TEXT(DATE(YEAR(AP4)+5,MONTH(AP4),DAY(AP4)),""DD-MMM-YYYY"")"
End If
End If
End If
End If
End If
End If
End With
End Sub
有人可以帮忙吗?
答案 0 :(得分:0)
我强烈建议您使用适当的缩进,并且可以使用@PreDestroy
来避免过多ElseIf
。
(我知道这不是一个答案,但在评论中指出太多,而且由于拼写错误,问题可能会因此而被关闭)
End If