30 Advanced Excel Tips for 2026

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

VBA Exit IF

30+ Advanced Excel Tips for 2026

No spam. Only Excel Stuff. God Promise. 😊

VBA has no Exit If. To skip the rest of an If block, put the code that should run in the other case in the Else branch, or reverse the test so the block runs only when it should:

If Range("A1").Value = "" Then
    Range("A1").Value = InputBox("Enter a value")
Else
    MsgBox "A1 already has a value."
End If

To leave more than the If, use the exit statement for the structure around it. Exit For and Exit Do leave a loop and carry on from the line after it; Exit Sub and Exit Function end the procedure and return to whatever called it.

A guard clause at the top of a procedure keeps the rest of the code out of an If altogether: If Range("A1").Value = "" Then Exit Sub stops the macro straight away when there’s nothing to work on.

If you jump out of an If with GoTo, code that reaches the label in the normal way runs it too. Without Exit Sub before the label, the code you meant to skip runs whenever the If didn’t jump.

In VBA, when you use the IF statement, you can use a GoTo statement to exit the IF. Let me clarify here: there’s no separate exit statement (like Exit If) that you can use with IF. So, you need to use GoTo to jump out of the IF before the End If line is reached.

Let’s look at an example to understand this.

vba-exit-if

In the above example, as you can see, we have used an IF statement to check if there’s a value in cell A1 or not. When you run this code, and there’s no value in cell A1, VBA will jump to the label “Lable1” and run the code under it. So, it will show an input box to enter the value in cell A1. And if there’s a value in the cell, it shows a message and the Exit Sub statement ends the code, so the input box doesn’t show up.

Sub myMacro()

If Range("A1") = "" Then
 GoTo Lable1
Else
 MsgBox "there's a value in the cell."
 Exit Sub
End If

Lable1:
Range("A1").Value = _
InputBox("Enter Value")

End Sub

There will be a few situations when you need to exit an IF statement while writing a VBA code. As you know, in an IF statement, VBA runs the code that you have mentioned for the condition that is true and then exits the statement automatically. So, you need to jump out only when you want to skip the rest of the code inside the IF block.

A label name starts with a letter, ends with a colon, and must be in the same procedure as the GoTo statement. Otherwise, you get the “Label not defined” error.

Write the Same Code without GoTo

In most cases, you don’t need GoTo at all. You can put the code that you want to run in the right part of the IF statement, and VBA skips the other part for you. Here’s the same example without a label:

Sub myMacro()
If Range("A1").Value = "" Then
Range("A1").Value = InputBox("Enter Value")
Else
MsgBox "There's a value in the cell."
End If
End Sub

This is easier to read, and Microsoft also suggests using structured statements like this instead of GoTo, as too many jumps make the code hard to follow. And when you have more than two conditions, use ElseIf to test them one by one; VBA runs only the first one that’s true.

Use Exit Sub to Leave the Procedure from an IF

When you want to stop the whole code if a condition is true, use Exit Sub inside the IF (or Exit Function in a function). This is a common way to check the input before the rest of the code runs:

Sub CheckInput()
If Range("A1").Value = "" Then
MsgBox "Please enter a value in cell A1."
Exit Sub
End If
Range("B1").Value = Range("A1").Value * 2
End Sub

Use Exit For or Exit Do When the IF Is in a Loop

If your IF statement is inside a loop, you can use Exit For (or Exit Do) inside the IF to stop the loop as soon as you find what you’re looking for. In the code below, the loop goes through cells A1 to A100 and stops at the first blank cell:

Sub FindFirstBlank()
Dim i As Long
For i = 1 To 100
If Cells(i, 1).Value = "" Then
MsgBox "The first blank cell is A" & i
Exit For
End If
Next i
End Sub

Frequently Asked Questions

Is There an Exit If Statement in VBA?

No. VBA has Exit Sub, Exit Function, Exit Property, Exit For and Exit Do, but no Exit If. If you write Exit If, the VB Editor shows a syntax error. Use GoTo, Exit Sub, or put the code in the right part of the IF statement instead.

How Do I Skip to the Next Loop Iteration from an IF?

VBA doesn’t have a Continue statement. You can put the rest of the loop’s code inside an IF block that runs only when the condition is false, or use GoTo with a label placed just before the Next line.

Is It Bad to Use GoTo in VBA?

It’s not wrong, but a lot of GoTo jumps make your code hard to read and debug. Use it when it keeps the code simple, and the most common use is On Error GoTo for error handling.

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