vba Excel VBA中IF语句中的多个条件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34884992/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Multiple conditions in an IF statement in Excel VBA
提问by Mark Tennant
Probably an easy one but my prog skills are limited. I've created an account entry tool and want to warn the user if they've entered a credit amount for an Expenditure type of which there are two types; "Restricted_Expenditure" and "Unrestricted Expenditure". Typically values of this type should be debits.
可能很简单,但我的编程技能有限。我创建了一个帐户输入工具,并希望警告用户是否为有两种类型的支出类型输入了信用金额;“Restricted_Expenditure”和“Unrestricted Expenditure”。通常这种类型的值应该是借方。
I can get it to work for one type in the statement, but not if I add the other expenditure type in an "or" statement.
我可以让它对语句中的一种类型起作用,但如果我在“或”语句中添加另一种支出类型,则不能。
Any help appreciated - is there an "Or If..." type function I could use?
任何帮助表示赞赏 - 是否有我可以使用的“或者如果...”类型的功能?
My code is
我的代码是
If inputWks.Range("d9") > 0 And inputWks.Range("d11") = "Restricted_Expenditure" Or "Unrestricted_Expenditure" Then
Dim Response As Integer
Response = MsgBox(prompt:="You've entered a credit amount against an expenditure type. If this is correct then press 'Yes' or else press 'No' to change", Buttons:=vbYesNo)
If Response = vbYes Then
GoTo Line1
Else
Exit Sub
End If
回答by Fadi
In VBA we can not use if jj = 5 or 6 thenwe must use if jj = 5 or jj = 6 then
在 VBA 中我们不能使用if jj = 5 or 6 then我们必须使用if jj = 5 or jj = 6 then
maybe this:
也许这个:
If inputWks.Range("d9") > 0 And (inputWks.Range("d11") = "Restricted_Expenditure" Or inputWks.Range("d11") = "Unrestricted_Expenditure") Then

