如果有多个and,嵌套的If,还是带有布尔值的If



我已经尝试了多种方法,但仍然没有得到所需的结果。我有一个带有多个复选框的UserForm。如果选中两个复选框,我想要一个答案,但如果选中第三个复选框则需要一个单独的答案。正确的方法是什么?嵌套Ifs:

Dim Cost As Range, SetUpCost As Range, Prices As Range
Set Cost = WB.Worksheets("Calculations").Range("F42")
Set Prices = WB.Worksheets("Calculations").Range("D42")
If QuarterlyCheck = True And SecurityLite = True Then
If NoSetUpCheck = False Then
SecurityLitePrice.Caption = "$" & Cost.Value * 4
SetUpFee.Caption = "$" & SetUpCost.Value
End If
ElseIf NoSetUpCheck = True Then
SecurityLitePrice.Caption = "$" & Prices.Value * 4
SetUpFee.Caption = ""
End If

或多个如果:

If QuarterlyCheck = True And SecurityLite = True And NoSetUpCheck = False Then
SecurityLitePrice.Caption = "$" & Cost.Value * 4
SetUpFee.Caption = "$" & SetUpCost.Value
End If
If QuarterlyCheck = True And SecurityLite = True And NoSetUpCheck = True Then
SecurityLitePrice.Caption = "$" & Prices.Value * 4
SetUpFee.Caption = ""
End If

两者都没有给我带来我需要的结果。

可能:

If QuarterlyCheck = True And SecurityLite = True Then
If NoSetUpCheck = True Then
SecurityLitePrice.Caption = "$" & Prices.Value * 4
SetUpFee.Caption = ""
Else 'Means NoSetUpCheck = False
SecurityLitePrice.Caption = "$" & Cost.Value * 4
SetUpFee.Caption = "$" & SetUpCost.Value
End If
Else
'Whatever else ....
End If

最新更新