IsEmpty / IsBlank Function in VBA

Written by

Mel Jenkins

Reviewed by

Steve Rynearson

Last updated on March 15, 2024

In this article, you will learn how to use the IsEmpty function in VBA to check if a cell is empty. If you want to do the same in Excel, a similar function is the IsBlank function. In this step-by-step tutorial, for all levels of Excel and VBA users, you will see how to use both functions.

 

Using the IsEmpty function in VBA

As we already mentioned in the introduction, the IsEmpty is the simple function in VBA which checks if a cell is empty. If the selected does not contain any value, the function will return Boolean TRUE. On the other side, if the cell contains a value, the function returns FALSE. Here is the code:

If IsEmpty(Sheet1.Range("A1").Value) = True Then

    Sheet1.Range("B1").Value = "The cell A1 is empty"

Else

    Sheet1.Range("B1").Value = "The value in A1 is " & Sheet1.Range("A1").Value

End If

In the example, we want to check if the cell A1 in the Sheet1 contains any value. Therefore, if the cell is empty, we will return “The cell A1 is empty” in the cell B1. If the cell contains a value, we will return the value of the cell A1 in the cell B1. Let’s run the code first with empty A1 and then with A1 containing some value:

Image 1. Using the IsEmpty in VBA with the empty cell

Image 2. Using the IsEmpty in VBA with populated cell

 

Using the IsBlank function in Excel

The IsBlank function also checks if the value of the cell is blank, but this function does not exist in VBA. We’ll see on similar examples how to check if the cell is blank in Excel, using this formula:

=ISBLANK(A1)

 

Image 3. Using the IsBlank in Excel with blank A1 cell

Image 4. Using the IsBlank in Excel with populated A1 cell

 

As you can see, we check if the cell A1 is blank and return the result of the function in the cell B1. In Image 3, the result of the function is Boolean TRUE. On the other side, in Image 4, the result of the function is FALSE, as the cell A1 is “11” and is not blank.

Examples of Excel VBA IsEmpty Function

Dim a As Variant
a = Null
MsgBox IsEmpty(a)

Result: False

Dim a As Variant
a = Empty
MsgBox IsEmpty(a)

Result: True

IsEmpty function can be used to check blank cells.

Sub IsEmpty_Example1()
    Dim cell As Range
    
    For Each cell In Range("A2:A5")
        cell.Offset(0, 1) = IsEmpty(cell)
    Next cell
End Sub

The result is as following.

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as


Learn More!
vba-free-addin

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)

Free Download

Return to VBA Code Examples