# VBA IsEmpty

Published on :

21 Aug, 2024

Blog Author :

N/A

Edited by :

Ashish Kumar Srivastav

Reviewed by :

Dheeraj Vaidya

IsEmpty is a worksheet function used to find out whether a given cell reference or a range of cells is empty or not. Since it is a worksheet function, we use the Application to use it in VBA. It is the worksheet method in VBA to use this function. This function comes under the logical lists of functions and returns "True" if the reference is empty.

## VBA IsEmpty Function

VBA IsEmpty is a logical function that tests whether the selected is empty or not. Since it is a logical function, it will return the results in Boolean values, i.e., TRUE or FALSE.

If the selected cell is empty, it will return TRUE, or else it will return FALSE.

This article will show you how to use the ISEMPTY function in VBA to check the cells using VBA codes.

##### Table of contents

### What Does ISEMPTY Function Do in VBA?

Often empty cells frustrate us from working efficiently on the worksheet. Finding the blank cells is not the hardest, but if empty cells hide them in the middle of the data, it takes a toll to find them.

To find the empty cells in Excel, we have the " ISBLANK " function as a worksheet function, but in VBA, it is called "ISEMPTY."

It works similarly to the worksheet function “ISBLANK”. Now, look at the below formula of the "ISEMPTY" function.

As we can see in the above image, it returns the result as Boolean, i.e., TRUE or FALSE.

### Examples of ISEMPTY Function in VBA

The following are examples of IsEmpty in VBA.

#### Example #1

Now, we will see the first practical example of "ISEMPTY." For this, take a look at the below image of the worksheet.

Now, we will apply Excel VBA ISEMPTY function to test all these.

**Step 1: **Define the variable **as Boolean**.

**Code:**

Sub IsEmpty_Example1() Dim K As Boolean End Sub

**Step 2: **Assign the value through VBA **ISEMPTY **function for this variable.

**Code:**

Sub IsEmpty_Example1() Dim K As Boolean K = IsEmpty( End Sub

**Step 3: **Expression is nothing but what is the cell we are testing. Now, we are testing the** A1 cell.**

**Code:**

Sub IsEmpty_Example1() Dim K As Boolean K = IsEmpty(Range("A1").Value) End Sub

**Step 4: **Show the value of this variable in the VBA **Msgbox**.

**Code:**

Sub IsEmpty_Example1() Dim K As Boolean K = IsEmpty(Range("A1").Value) MsgBox K End Sub

Run this code to check the result.

Since there is a value in cell A1, we got the result as FALSE.

Now, we will change the cell reference from **A1 to A5**.

**Code:**

Sub IsEmpty_Example1() Dim K As Boolean K = IsEmpty(Range("A5").Value) MsgBox K End Sub

Run this code to see the result.

We got the result as TRUE. The referenced cell A5 is an empty cell, so we got the result as "TRUE."

Now, we will test **cell A8**.

**Code:**

Sub IsEmpty_Example1() Dim K As Boolean K = IsEmpty(Range("A8").Value) MsgBox K End Sub

Run this code to see the result.

We got the result as FALSE even though there is no value in cell A8.

Now, is it an error result from the ISEMPTY formula?

No… Absolutely No!

When examining cell A8, there was a space character inside the cell that is not easy to see with bare eyes.

So, the conclusion is even space is considered a character in Excel and VBA language.

#### Example #2 - Combination of VBA ISEMPTY with IF Condition

The real usage of the function "ISEMPTY" is admirable when we use it with other logical functions.

Especially when we use it with IF conditions, we can derive many useful results from it.

For this demonstration, take a look at the below example.

In the "Status" column, if the "PF Status" column is empty, we need the value "No Update." If there is any value, we need the values as "Collected Updates."

Remember here that we do not need the default result of TRUE or FALSE. We need our results here. We need to use Excel VBA ISEMPTY with IF conditions to have our results.

**Step 1: **Open **IF** condition.

**Code:**

Sub IsEmpty_Example2() If End Sub

**Step 2: **Inside the IF condition, open the** ISEMPTY function.**

**Code:**

Sub IsEmpty_Example2() If IsEmpty( End Sub

**Step 3: **The first logical test is **cell B2 value** is empty or not.

**Code:**

Sub IsEmpty_Example2() If IsEmpty(Range("B2").Value) Then End Sub

**Step 4: **If the logical test in excel VBA is TRUE, i.e., if the cell is empty, we need the resultas **"No Update" **in cell C2.

**Code:**

Sub IsEmpty_Example2() If IsEmpty(Range("B2").Value) Then Range("C2").Value = "No Update" End Sub

**Step 5: **If the logical test is FALSE, we need the result in cell C2 as “**Collected Updates**.”

**Code:**

Sub IsEmpty_Example2() If IsEmpty(Range("B2").Value) Then Range("C2").Value = "No Update" Else Range("C2").Value = "Collects Updates" End If End Sub

We have completed it now.

Run the code to get the result.

We got the **"Collected Updates"** result because we have the non-empty cell in B2.

Now, similarly, apply the code for other cells to test.

**Code:**

Sub IsEmpty_Example2() If IsEmpty(Range("B2").Value) Then Range("C2").Value = "No Update" Else Range("C2").Value = "Collects Updates" End If If IsEmpty(Range("B3").Value) Then Range("C3").Value = "No Update" Else Range("C3").Value = "Collected Updates" End If If IsEmpty(Range("B4").Value) Then Range("C4").Value = "No Update" Else Range("C4").Value = "Collected Updates" End If End Sub

Run this code to have the results.

In cell C3, we got the result as **"No Update"** because there is no value in cell B3, i.e., an empty cell. Since the logical formula returned TRUE, we got the individual result.

#### Example #3 - Alternative to VBA ISEMPTY Function

We have an alternative to the ISEMPTY function; without applying the Excel VBA ISEMPTY function, we can test the cell.

For an example, look at the below code.

**Code:**

Sub IsEmpty_Example3() If Range("B2").Value = "" Then Range("C2").Value = "No Update" Else Range("C2").Value = "Collected Updates" End If End Sub

The line of code **Range(“B2″).Value = ” ” **means whether the cell B2 cell is equal to empty or not.

Double Quotes ("”) represent an empty cell or not if the empty result is TRUE or else FALSE.

### Recommended Articles

This article has been a guide to VBA ISEMPTY function. Here, we learned how to use the VBA ISEMPTY function in Excel, the Combination of IsEmpty with the IF condition, some practical examples, and a downloadable Excel template. Below are some useful Excel articles related to VBA: -