【发布时间】:2020-06-03 21:13:01
【问题描述】:
我已经尝试了多种方法,但仍然没有得到我需要的结果。我有一个带有多个复选框的用户窗体。如果选中了两个复选框,我想要一个答案,但如果选中第三个复选框,则需要一个单独的答案。这样做的正确方法是什么? 嵌套 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:
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
两者都没有得到我需要的结果。
【问题讨论】:
-
如果选中第三个复选框,是否会取代同时选中复选框 1 和 2?那么
1 = True and 2 = True或1 = False and 2 = False是否与3 = true无关? -
不,必须选中复选框 1 和 2 以与用户窗体上的其他相关子项一致。选中 3(或取消选中)会改变结果。
标签: vba if-statement boolean