mardi 19 janvier 2016

Multiple conditions in an IF statement in Excel VBA

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

Aucun commentaire:

Enregistrer un commentaire