## VBA Logical Operators: AND, OR, NOT, IF NOT in Excel VBA - Shikshaglobe

Content Creator:

VBA logical operators evaluate data to produce a result of either True or False. The main logical operators used in VBA are AND, OR, and NOT.

The AND operator takes two Boolean values and returns True if both values are True, otherwise, it returns False. For example, the following code will return True because both conditions are met:

If condition1 And condition2 Then

The OR operator takes two Boolean values and returns True if either value is True, otherwise, it returns False. For example, the following code will return True because at least one condition is met:

If condition1 Or condition2 Then

The NOT operator takes a single Boolean value and reverses it, so if the value is True then it returns False and vice versa. For example, the following code will return False because the condition is not met:

If Not condition1 Then

VBA Logical Operators allow you to make decisions in your code. The most common operators are AND, OR, and NOT. You can use these operators to combine multiple conditions. For example, you could use the AND operator to check if a cell contains a value greater than 10 AND less than 20.

1. AND Operator (AndAlso):

The AND operator, represented by And or AndAlso, is used to combine multiple conditions. It returns True only if all the specified conditions are True. Otherwise, it returns False.

2. OR Operator (OrElse):

The OR operator, represented by Or or OrElse, is used to combine multiple conditions. It returns True if at least one of the specified conditions is True. It returns False only if all the conditions are False.

3. NOT Operator:

The NOT operator, represented by Not, is used to reverse the logical value of a condition. If a condition is True, NOT makes it False, and if a condition is False, NOT makes it True.

4. IF NOT Statement:

The IF NOT statement is a conditional statement that checks if a condition is False. If the condition is False, the code inside the IF NOT block is executed.

These logical operators are fundamental for creating decision-making structures in Excel VBA code, allowing you to create dynamic and responsive programs that can handle various scenarios and conditions.

The IF NOT operator is a handy way to reverse the result of a test. For example, if you wanted to check if a cell did NOT contain the value 10, you could use the following code: IF NOT(cellValue=10). This would return TRUE if the cell value was not equal to 10.

Excel VBA Logical Operators allow your code to make decisions based on multiple criteria. The most common logical operators are AND, OR, and NOT. You can use these operators in both Excel worksheet formulas and VBA code.

The AND operator returns TRUE if all its operands are TRUE, and FALSE if any of its operands are FALSE.

The OR operator returns TRUE if any of its operands are TRUE, and FALSE if all of its operands are FALSE.

The NOT operator reverses the value of its operand. If the operand is TRUE, NOT return FALSE. If the operand is FALSE, NOT return TRUE.

Succeed VBA Logical Operators

Suppose you need to handle a client request. For that, you need to initially verify whether the arranged item exists or not. Assuming it does, you likewise need to check in the event that the amount available is sufficient. Legitimate administrators prove to be useful in such cases. Legitimate administrators are utilized to assess more than one condition.

VBA Logical Operators Example Source Code

For straightforwardness, we will think about hard-coded numbers.

Add ActiveX buttons to the sheet from the "Supplement choice."

Set the properties as displayed in the picture beneath

#### Experience the difference

VBA If AND Operator

"On the off chance that (1 = 1) And (0 = 0" the assuming assertion utilizes the AND intelligent administrator to join two circumstances (1 = 1) And (0 = 0). In the event that the two circumstances are valid, the code above the 'Else' catchphrase is executed. In the event that the two circumstances are false, the code underneath the 'Else' catchphrase is executed.

VBA If OR Operator

"On the off chance that (1 = 1) Or (5 = 0" the assuming assertion utilizes the OR intelligent administrator to join two circumstances (1 = 1) And (5 = 0). In the event that any of the circumstances is valid, the code above Else catchphrase is executed. Assuming the two circumstances are misleading, the code underneath the Else watchword is executed.

VBA If NOT Operator

"On the off chance that Not (0 = 0" the VBA If Not capability utilizes the NOT sensible administrator to discredit the aftereffect of the assuming assertion condition. Assuming that the circumstances are valid, the code underneath the 'Else' catchphrase is executed. Assuming the condition is valid, the code above Else watchword is executed.

### Mahatma Gandhi University

Location: Soreng ,Sikkim , India
Approved: UGC
Course Offered: UG and PG

### MATS University

Location: Raipur, Chhattisgarh, India
Approved: UGC
Course Offered: UG and PG

### Kalinga University

Location: Raipur, Chhattisgarh,India
Approved: UGC
Course Offered: UG and PG

### Vinayaka Missions Sikkim University

Location: Gangtok, Sikkim, India
Approved: UGC
Course Offered: UG and PG

### Sabarmati University

Approved: UGC
Course Offered: UG and PG

### Arni University

Approved: UGC
Course Offered: UG and PG

### Capital University

Location: Jhumri Telaiya Jharkhand,India
Approved: UGC
Course Offered: UG and PG

### Glocal University

Location: Saharanpur, UP, India.
Approved: UGC
Course Offered: UG and PG

### Himalayan Garhwal University

Location: PG, Uttarakhand, India
Approved: UGC
Course Offered: UG and PG

### Sikkim Professional University

Location: Sikkim, India
Approved: UGC
Course Offered: UG and PG

### North East Frontier Technical University

Location: Aalo, AP ,India
Approved: UGC
Course Offered: UG and PG