我希望就IfVBA 中大量嵌套语句的更好解决方案获得一些建议。由于可能的条件数量,该If语句变得非常大。我正在考虑使用For循环,但这似乎仍然需要大量If条件,我也想到了 a Select Case,但这也不起作用。
下面的代码显示了我如何为If语句和大多数条件设置变量。任何简化此代码的帮助将不胜感激。
If wsCalc.Range("LenderComplete") <> vbNullString Then f = 1
If wsCalc.Range("ProcessorComplete") <> vbNullString Then g = 1
If wsCalc.Range("KeyerComplete") <> vbNullString Then h = 1
If wsCalc.Range("CheckerComplete") <> vbNullString Then i = 1
If f <> 1 And g <> 1 And h <> 1 And i <> 1 Then
ContLoanFile.ContinueLP.BackColor = vbYellow
With ContLoanFile.Label7
.Caption = "Lender items NOT complete." & vbNewLine & "Processor items NOT complete." & vbNewLine & "Keyer items NOT complete." & vbNewLine & "Checker items NOT complete."
.Font.Size = 9
End With
If f = 1 And g <> 1 And h <> 1 And i <> 1 Then
ContLoanFile.ContinueLP.BackColor = vbYellow
With ContLoanFile.Label7
.Caption = "Lender items COMPLETE." & vbNewLine & "Processor items COMPLETE." & vbNewLine & "Keyer items NOT complete." & vbNewLine & "Checker items NOT complete."
.Font.Size = 9
End With
If f = 1 And g = 1 And h <> 1 And i <> 1 Then
ContLoanFile.ContinueLP.BackColor = vbYellow
With ContLoanFile.Label7
.Caption = "Lender items COMPLETE." & vbNewLine & "Processor items COMPLETE." & vbNewLine & "Keyer items NOT complete." & vbNewLine & "Checker items NOT complete."
.Font.Size = 9
End With
If f = 1 And g = 1 And h = 1 And i <> 1 Then
ContLoanFile.ContinueLP.BackColor = vbYellow
With ContLoanFile.Label7
.Caption = "Lender items COMPLETE." & vbNewLine & "Processor items COMPLETE." & vbNewLine & "Keyer items COMPLETE." & vbNewLine & "Checker items NOT complete."
.Font.Size = 9
End With
If f = 1 And g = 1 And h = 1 And i = 1 Then
ContLoanFile.ContinueLP.BackColor = vbYellow
With ContLoanFile.Label7
.Caption = "Lender items COMPLETE." & vbNewLine & "Processor items COMPLETE." & vbNewLine & "Keyer items COMPLETE." & vbNewLine & "Checker items COMPLETE."
.Font.Size = 9
End With
If f <> 1 And g = 1 And h = 1 And i = 1 Then
ContLoanFile.ContinueLP.BackColor = vbYellow
With ContLoanFile.Label7
.Caption = "Lender items NOT complete." & vbNewLine & "Processor items COMPLETE." & vbNewLine & "Keyer items COMPLETE." & vbNewLine & "Checker items COMPLETE."
.Font.Size = 9
End With
If f = 1 And g <> 1 And h = 1 And i = 1 Then
ContLoanFile.ContinueLP.BackColor = vbYellow
With ContLoanFile.Label7
.Caption = "Lender items COMPLETE." & vbNewLine & "Processor items NOT complete." & vbNewLine & "Keyer items COMPLETE." & vbNewLine & "Checker items COMPLETE."
.Font.Size = 9
End With