VBA ISNULL

Article byJeevan A Y
Edited byAshish Kumar Srivastav
Reviewed byDheeraj Vaidya, CFA, FRM

VBA ISNULL Function

ISNULL in VBA is a logical function used to determine whether a given reference is empty or NULL. That is why the name ISNULL is an inbuilt function that gives us True or False as a result. Based on the result, we can arrive at conclusions. For example, if the reference is empty, it returns a True or False value.

Finding the errors is not the easiest job in the world, especially in a huge spreadsheet finding them in between the data is almost impossible. Finding the NULL value in the worksheet is one of the frustrating jobs. To resolve this problem, we have a function called “ISNULL” in VBA.

This article will show you how to use the “ISNULL” function in VBA.

ISNULL is a built-in function in VBA and is categorized as an Information function in VBA that returns the result in Boolean type, i.e., either TRUE or FALSE.

If the testing value is “NULL, ” it returns TRUE or will return FALSE. This function is available only with VBA. We cannot use this with the Excel worksheet function. However, we can use this function in any sub procedure and function procedure.

VBA ISNULL

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

Syntax

Take a look at the syntax of the ISNULL function.

ISNULL Formula

–>> If you want to learn Excel VBA professionally, then our VBA Basic Course (16+ hours) is the perfect solution. In our Basic Excel VBA course you learn the skill of automating tasks using Variables, Data Types, Ranges, and Cells in VBA. Master Control Structures, including Conditional Statements and Loops, and discover techniques for manipulating data through sorting, filtering, and formatting. By the end of the course, you will be able to apply your acquired skills to real projects, culminating in an Excel VBA project which will solidify your ability to create efficient, automated solutions.

Examples of ISNULL Function in VBA

Below are examples of the VBA ISNULL function.

Example #1

Start with a simple VBA ISNULL example. First, check whether the value Excel VBA is NULL. The below code is the demonstration code for you.

Code:

Sub IsNull_Example1()
'Check the value "Excel VBA" is null or not
'Declare two Variables
'One is to store the value
'Second one is to store the result

Dim ExpressionValue As String
Dim Result As Boolean

ExpressionValue = "Excel VBA"

Result = IsNull(ExpressionValue)

'Show the result in message box
MsgBox "Is the expression is null? : " & Result, vbInformation, "VBA ISNULL Function Example"

End Sub
VBA ISNULL Example 1

When you run this code using the F5 key or manually, we will get the result as “FALSE” because the supplied value “Excel VBA” is not a NULL value.

VBA ISNULL Example 1-1

Example #2

Now, check whether the value “47895” is NULL or not. Below is the code to demonstrate the formula.

Code:

Sub IsNull_Example2()
'Check the value 47895 is null or not

'Declare two Variables
'One is to store the value
'Second one is to store the result
Dim ExpressionValue As String
Dim Result As Boolean

ExpressionValue = 47895

Result = IsNull(ExpressionValue)

'Show the result in message box
MsgBox "Is the expression is null? : " & Result, vbInformation, "VBA ISNULL Function Example"

End Sub
VBA ISNULL Example 2

Even this code will return the result as FALSE because the supplied expression value “47895” isn’t the NULL value.

VBA ISNULL Example 2-1

Example #3

Now, check whether the empty value is NULL or not. For example, the below code tests whether the empty string is NULL or not.

Code:

Sub IsNull_Example3()
'Check the value "" is null or not

'Declare two Variables
'One is to store the value
'Second one is to store the result
Dim ExpressionValue As String
Dim Result As Boolean

ExpressionValue = ""

Result = IsNull(ExpressionValue)

'Show the result in message box
MsgBox "Is the expression is null? : " & Result, vbInformation, "VBA ISNULL Function Example"

End Sub
Example 3

This formula also returns FALSE because VBA treats the empty value as a variable that is uninitialized yet and one cannot consider it as a NULL value.

Example 3-1

Example #4

Now, we will assign the word “Null” to the variable “ExpressionValue” and see the result.

Code:

Sub IsNull_Example4()
'Check the value "" is null or not

'Declare two Variables
'One is to store the value
'Second one is to store the result
Dim ExpressionValue As Variant
Dim Result As Boolean

ExpressionValue = Null

Result = IsNull(ExpressionValue)

'Show the result in message box
MsgBox "Is the expression is null? : " & Result, vbInformation, "VBA ISNULL Function Example"

End Sub
VBAISNULL Example 4

Run this code manually or use the F5 key. Then, this code will return TRUE because the supplied value is NULL.

VBA ISNULL Example 4-1

You can download this VBA ISNULL Function template here – VBA ISNULL Excel Template

Recommended Articles

This article has been a guide to VBA ISNULL. Here, we learn how to use the VBA ISNULL function to find the null values in Excel Worksheet, along with practical examples and downloadable codes. Below are some useful Excel articles related to VBA: –