WallStreetMojo

WallStreetMojo

WallStreetMojo

MENUMENU
  • Blog
  • Free Video Tutorials
  • Courses
  • All in One Bundle
  • Login
Home » Excel, VBA & Power BI » Learn VBA » VBA ISNULL

VBA ISNULL

By Jeevan A YJeevan A Y | Reviewed By Dheeraj VaidyaDheeraj Vaidya, CFA, FRM

VBA ISNULL Function

ISNULL in VBA is a logical function which is used to determine whether a given reference is empty or NULL or not that is why the name ISNULL, this is an inbuilt function which gives us true or false as a result, based on the result we can arrive to conclusions, if the reference is empty it returns true value else false value.

Finding the error isn’t 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.

In this article, we 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 which returns the result in Boolean type i.e. either TRUE or FALSE.

If the testing value is “NULL” then it returns TRUE or else it will return FALSE. This function is available only with VBA and we cannot use this with Excel worksheet function. This function can be used in any subprocedure and function procedure.

VBA ISNULL

Syntax

Take a look at the syntax of the ISNULL function.

Popular Course in this category
Sale
VBA Training (3 Courses, 12+ Projects)
4.6 (247 ratings)
3 Courses | 12 Hands-on Projects | 43+ Hours | Full Lifetime Access | Certificate of Completion
View Course

ISNULL Formula

  • This function has only one argument i.e. “Expression”.
  • An expression is nothing but the value we are testing and the value could be a cell reference, direct value, or variable assigned value as well.
  • The Null indicates that expression or variable doesn’t contain valid data. Null is not the empty value because VBA thinks variable value has not yet been started and doesn’t treat as Null.

Examples of ISNULL Function in VBA

Below are the examples of the VBA ISNULL Function.

Example #1

Start off with a simple VBA ISNULL example. Check whether the value “Excel VBA” is NULL or not. 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 then, 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 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. Below code is to test 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 is not yet initialized and cannot be considered as a NULL value.

Example 3-1

Example #4

Now I will assign the word “Null” to the variable “ExpressionValue” and see what the result is.

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 using the F5 key then, this code will return TRUE as a result 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 has been a guide to VBA ISNULL. Here we learn how to use 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 –

  • CSTR in Excel VBA
  • Count Function in VBA
  • AutoFill in VBA
  • Random Numbers in VBA
  • VBA Save As
0 Shares
Share
Tweet
Share
VBA Training (3 Courses, 12+ Projects)
  • 3 Courses
  • 12 Hands-on Projects
  • 43+ Hours
  • Full Lifetime Access
  • Certificate of Completion
LEARN MORE >>
Primary Sidebar
Footer
COMPANY
About
Reviews
Contact
Privacy
Terms of Service
RESOURCES
Blog
Free Courses
Free Tutorials
Investment Banking Tutorials
Financial Modeling Tutorials
Excel Tutorials
Accounting Tutorials
Financial Statement Analysis
COURSES
All Courses
Financial Analyst All in One Course
Investment Banking Course
Financial Modeling Course
Private Equity Course
Venture Capital Course
Excel All in One Course

Copyright © 2021. CFA Institute Does Not Endorse, Promote, Or Warrant The Accuracy Or Quality Of WallStreetMojo. CFA® And Chartered Financial Analyst® Are Registered Trademarks Owned By CFA Institute.
Return to top

WallStreetMojo

Download Coursera IPO Financial Model

By continuing above step, you agree to our Terms of Use and Privacy Policy.
WallStreetMojo

Free Excel Course

Excel functions, Formula, Charts, Formatting creating excel dashboard & others

* Please provide your correct email id. Login details for this Free course will be emailed to you

Book Your One Instructor : One Learner Free Class
Let’s Get Started
Please select the batch
Saturday - Sunday 9 am IST to 5 pm IST
Saturday - Sunday 9 am IST to 5 pm IST

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

WallStreetMojo

Free Excel Course

Excel functions, Formula, Charts, Formatting creating excel dashboard & others

* Please provide your correct email id. Login details for this Free course will be emailed to you

Login

Forgot Password?

Coursera IPO Financial Model & Valuation Free Download