Logical operators in VBA -And, Or,and Not. - VBA For Excel

VBA supports three logical operators: And, Or,and Not. They let you combine two or more comparison tests into a single compound comparison.For example,suppose we wanted to implement the following code:

If(myCell.Value =6) Then
If (Activecell.Value>0) Then
MsgBox "Done"
End If
End If

The two comparison tests can be replaced with one test as:

If (myCell.Value =6) And (ActiveCell.value >0) Then

The logical operators

The logical operators

Self-assessment exercise

Rewrite the following If to eliminate the Not and to clarify the code:

If Not(x < 20) Or Not(y >= 20) Then

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

VBA For Excel Topics