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.
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
Another way to get an Excel IF to test multiple conditions is by using an array formula. To complete an array formula correctly, press the Ctrl + Shift + Enter keys together. In Excel 365 and Excel 2021, this also works as a regular formula due to support for dynamic arrays.
In VBA, you can use one IF statement inside another IF statement to create nested IFs. In simple words, you can execute one test statement using IF based on the result of another IF statement. In this kind of conditional statement, you need to test complex conditions.
Conditional Statements are the If ....Then statement, with the Else or ElseIf, and the Select case statement. The form is: [expression] [relational operator] [expression] where in 1 condition you have the Conditional operators and in 2 or more the Logical operators.
Else statements can be nested to as many levels as you need.
In VBA we can not use if jj = 5 or 6 then
we must use 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With