gpt4 book ai didi

vba - 更改 IF 语句以提高效率

转载 作者:行者123 更新时间:2023-12-04 21:34:52 43 4
gpt4 key购买 nike

我有很多情况会导致相同的消息框警报。
有没有比做几个 if 语句更简单/更好的解决方案?

      PRODUCTS            BOX1     BOX2       BOX3
--------------------------------------------------
|Apples, Oranges, | X | x | |
|Grapes, Peaches | x | x | |
|------------------------------------------------|
|Wheat | x | x | x |
|-------------------------------------------------
|Peanuts | | x | |
--------------------------------------------------

If product = "Apples" or product = Oranges or product = Grapes or products = Peaches then
If box = "box1" or box = "box2" then
msgbox "Your box may require approval"
End If
End If

If product = "Wheat" then
If box = "box1" or box = "box2" or box = "box3" then
msgbox "Your box may require approval"
End If
End If

If product = "Peanuts" then
If box = "box2" then
msgbox "Your box may require approval"
End If
End If

最佳答案

你可以这样做:

Select Case product
Case "Apples", "Oranges", "Grapes", "Peaches", "Wheat", "Peanuts"
Select Case box
Case "box1", "box2", "box3":
If product = "Wheat" Or box = "box2" Or (product <> "Peanuts" And box <> "box3") Then
MsgBox "Your box may require approval"
End If
End Select

关于vba - 更改 IF 语句以提高效率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40982692/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com