[vba] 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

This question is related to vba excel if-statement

The answer is


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

Examples related to vba

Copy filtered data to another sheet using VBA Better way to find last used row Check if a value is in an array or not with Excel VBA Creating an Array from a Range in VBA Excel: macro to export worksheet as CSV file without leaving my current Excel sheet VBA: Convert Text to Number What's the difference between "end" and "exit sub" in VBA? Rename Excel Sheet with VBA Macro Extract Data from PDF and Add to Worksheet Quicker way to get all unique values of a column in VBA?

Examples related to excel

Python: Pandas pd.read_excel giving ImportError: Install xlrd >= 0.9.0 for Excel support Converting unix time into date-time via excel How to increment a letter N times per iteration and store in an array? 'Microsoft.ACE.OLEDB.16.0' provider is not registered on the local machine. (System.Data) How to import an Excel file into SQL Server? Copy filtered data to another sheet using VBA Better way to find last used row Could pandas use column as index? Check if a value is in an array or not with Excel VBA How to sort dates from Oldest to Newest in Excel?

Examples related to if-statement

How to use *ngIf else? SQL Server IF EXISTS THEN 1 ELSE 2 What is a good practice to check if an environmental variable exists or not? Using OR operator in a jquery if statement R multiple conditions in if statement Syntax for an If statement using a boolean How to have multiple conditions for one if statement in python Ifelse statement in R with multiple conditions If strings starts with in PowerShell Multiple conditions in an IF statement in Excel VBA