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 codesUsing VBA CodesVBA code refers to a set of instructions written by the user in the Visual Basic Applications programming language on a Visual Basic Editor (VBE) to perform a specific task.read more.

You are free to use this image on you website, templates, etc., Please provide us with an attribution linkHow to Provide Attribution?Article Link to be HyperlinkedFor eg:Source: VBA IsEmpty (wallstreetmojo.com)

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.

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.

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.

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.

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.

Sub IsEmpty_Example1() Dim K As Boolean

K = IsEmpty(Range(“A8”).Value) MsgBox K

End Sub

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.

Sub IsEmpty_Example2()

If

End Sub

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

Sub IsEmpty_Example2()

If IsEmpty(

End Sub

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

Sub IsEmpty_Example2()

If IsEmpty(Range(“B2”).Value) Then

End Sub

Step 4: If the logical test in excelLogical Test In ExcelA logical test in Excel results in an analytical output, either true or false. The equals to operator, “=,” is the most commonly used logical test.read more VBA is TRUE, i.e., if the cell is empty, we need the resultas “No Update” in cell C2.

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.”

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.

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.

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.

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: –

  • Boolean in VBAFalse Function in ExcelOFFSET in VBADate Function in VBA