30 Advanced Excel Tips for 2026

Excel Champs / VBA / VBA IF Not
By Puneet Gogia (Microsoft MVP)

VBA IF Not

30+ Advanced Excel Tips for 2026

No spam. Only Excel Stuff. God Promise. 😊

Not reverses a test, so the block runs when the condition is False. If Not IsEmpty(Range("A1")) Then runs when A1 has something in it, and If Not IsNumeric(Range("A1").Value) Then runs when A1 isn’t a number.

The most common use is with objects. If Not rng Is Nothing Then checks that a Find or Set actually returned a range. In a Worksheet_Change event, If Not Intersect(Target, Range("B2:B100")) Is Nothing Then runs only when the changed cell is inside B2:B100.

For a plain comparison, <> is clearer: If ActiveSheet.Name <> "Data" Then does the same as If Not ActiveSheet.Name = "Data" Then and reads more easily. With more than one condition, use brackets to show what Not applies to: If Not (x > 0 And y > 0) Then.

Use Not only with True/False values. With a number, it flips the bits, and any result other than 0 counts as True, so If Not InStr(text, "x") Then runs whether or not “x” is found. Write If InStr(text, "x") = 0 Then instead.

In VBA, when you use the IF statement, it executes a line of code if the condition you have specified to test is TRUE. But when you use the NOT operator with IF, it checks if the condition you have specified is not TRUE and executes the code based on that.

It’s like making the IF statement opposite, TRUE into FALSE, and FALSE into TRUE.

Let’s say you want to test if A < B, and if this condition is true, the test returns TRUE, right? But when you use IF NOT A < B, it returns FALSE.

Below is the syntax of IF NOT. The code after Then runs when the condition is FALSE:

If Not condition Then
' code to run when the condition is FALSE
Else
' code to run when the condition is TRUE
End If

The Else part is optional, just like in a normal IF statement.

Note: NOT is a logical operator.

Examples to Use VBA IF NOT

Here we will see a simple example to understand it:

example-to-use-vba-if-not
Sub myMacro()

Dim A As Range, B As Range
Set A = Range("A1")
Set B = Range("B1")

If Not A < B Then
    MsgBox "A is not less than B."
Else
    MsgBox "A is less than B."
End If
   
End Sub

In the above code, you have used the NOT operator to test whether A is not less than B (in other words, whether A is greater than or equal to B).

If you look at the condition statement, you can understand that the actual condition is whether A is less than B, but as we have used the NOT operator, it returns FALSE when that condition is TRUE, and VBA runs the Else part.

Here’s another example that you can use to understand it.

Sub myMacro()

If Not ActiveSheet.Name = Sheets("Sheet1").Name Then
    Sheets("Sheet1").Activate
End If

End Sub

Now, in this code, you have used NOT with IF to see if the active sheet is Sheet1 or not, and if it is not, the line of code that we have specified will activate Sheet1.

You can write the same test with the not equal to operator (<>) as well, and it’s a bit easier to read:

If ActiveSheet.Name <> "Sheet1" Then
Sheets("Sheet1").Activate
End If

IF NOT with Is Nothing

This is where you’ll use IF NOT the most. When you search for a value with the Find method, VBA returns Nothing if it can’t find it. So you use If Not … Is Nothing to run the code only when the value is found:

Sub FindValue()
Dim myCell As Range
Set myCell = Range("A1:A100").Find(What:="Excel")
If Not myCell Is Nothing Then
MsgBox "Found in cell " & myCell.Address
Else
MsgBox "Value not found."
End If
End Sub

IF NOT with IsEmpty, IsNumeric and IsDate

You can also use NOT with the information functions to check a value before you use it. In the code below, the first test shows a message if cell A1 is not empty, and the second one stops the code if cell B1 doesn’t have a number:

Sub CheckCells()
If Not IsEmpty(Range("A1").Value) Then
MsgBox "Cell A1 has a value."
End If
If Not IsNumeric(Range("B1").Value) Then
MsgBox "Please enter a number in cell B1."
Exit Sub
End If
Range("C1").Value = Range("B1").Value * 2
End Sub

Keep in mind that IsNumeric returns TRUE for a blank cell, so if B1 can be empty, test it with IsEmpty as well.

IF NOT with AND and OR

NOT works only on the condition that comes right after it. So, when you have more than one condition, use parentheses to tell VBA what to reverse:

If Not (Range("A1").Value > 10 And Range("B1").Value > 10) Then
MsgBox "At least one value is 10 or less."
End If

Here, NOT reverses the result of both conditions together. Without the parentheses, NOT would apply only to the first condition and give you a different result.

A Common Mistake: NOT with a Number

NOT works as you expect only with TRUE and FALSE. When you use it with a number, VBA flips the bits of that number, so NOT 1 gives -2 and NOT 5 gives -6, and both of these count as TRUE in an IF statement. That’s why a code like If Not InStr(…) Then doesn’t work: InStr returns a position (a number), not TRUE or FALSE. Compare the result with 0 instead:

If InStr(Range("A1").Value, "Excel") = 0 Then
MsgBox "The text doesn't have the word Excel."
End If

Frequently Asked Questions

Is There an IFNOT Keyword in VBA?

No. You write the IF statement and the NOT operator separately, as “If Not condition Then”.

Should I Use NOT or the <> Operator?

Both give you the same result for a single comparison. The <> operator is easier to read for checking that a value is not equal to something, while NOT is the only way to reverse a test like Is Nothing, IsEmpty or a TRUE/FALSE variable.

Can I Use NOT with a Boolean Variable?

Yes. If you have a variable that holds TRUE or FALSE, like isDone, you can write If Not isDone Then, and the code runs when the variable is FALSE.

Puneet Gogia

Written by

Puneet Gogia

Microsoft MVP — Excel · Founder, Excel Champs

Twelve years of teaching Excel, and a decade before that using it as a data analyst. Every tutorial here is written from a file I actually built.

3M+ readers helped
1,000+ tutorials written
Since 2015 teaching Excel