EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home VBA VBA Resources VBA Error Handling Functions VBA IsError
 

VBA IsError

Madhuri Thakur
Article byMadhuri Thakur

VBA IsError

Excel VBA IsError

There are many types of functions in VBA. One of them is Excel VBA IsError. This function can be termed as an informative function because it provides us information as it is a logical function. This function tells us whether a given value contains an error or not. As I said above that it is a logical function means the value or the output generated by this function is either true or false. So how does this function works? We supply the expression to this function and when the expression is turned to be a simple integer or a value in the calculation then the Boolean output by this function is False however if the function returns an error then the Boolean result for this function would be True. True meaning the value or expression does not represent or is not an error while False meaning the value or the expression is an error.

 

 

Syntax:

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Iserror (Expression)

How to Use VBA IsError Function?

In these examples, we have seen that there are plenty of ways to use the IsError function in VBA. They are as follows,

  1. We can use the IsError function on a range of cells and check whether the cell has an error or not.
  2. We can also change a perfect value to an error and test it with the IsError function.
  3. On the other hand we can also use the expression directly in the code itself.
You can download this VBA IsError Excel Template here – VBA IsError Excel Template

Example #1

Let us begin with a basic example, in this example we will take a reference of a cell value from sheet of excel and test whether it contains an error or not. For this, follow the below steps:

Step 1: Insert a new module inside Visual Basic Editor (VBE). Click on Insert tab > select Module.

Insert Module

Step 2: Once we have a module in our project explorer we can begin with our example, Write the subprocedure of VBA IsError Function.

Code:

Sub Example1()

End Sub

VBA IsError Example 1-1

Step 3: Now let us use A2 cell for reference and check whether the value in it is an error or not, currently the cell doesn’t have any value. We will use the Msgbox function to display.

Code:

Sub Example1()

MsgBox IsError(Sheet1.Range("A1")), vbOKOnly, "Does cell A2 contain an error?"

End Sub

VBA IsError Example 1-2

Step 4: When we execute the above code by pressing function key F5 and to run the code, click on the Play button located below the menu bar.

VBA IsError Example 1-3

Example #2

Now let us use the concept where we can turn a variable with value to an error. In the following example, we will test two variables one we know for sure is not an error and another variable which we will convert into an error and check with the IsError function. For this, follow the below steps:

Step 1: Let us begin further in the same module from above and can declare another subprocedure.

Code:

Sub Example2()

End Sub

VBA IsError Example 2-1

Step 2: Now let us declare two different variables in the procedure.

Code:

Sub Example2()

Dim var1, var2
Dim isErr1 As Boolean
Dim isErr2 As Boolean

End Sub

Two Different Variables Example 2-2

Step 3: Now let us assign the first variable with a general value and for the second variable we will change the value to an error and then test it with the function known as IsError.

Code:

Sub Example2()

Dim var1, var2
Dim isErr1 As Boolean
Dim isErr2 As Boolean
var1 = 10
isErr1 = IsError(var1)
var2 = CVErr(11)
isErr2 = IsError(var2)
MsgBox isErr2

End Sub

VBA IsError Example 2-3

Step 4: When we execute the above code by pressing function key F5 and to run the code, click on the Play button.

VBA IsError Example 2-4

We have true as a result because the expression in the function was the second variable and which is an error since this function is an informative function it gave us the result as yes the value in the function is an error.

Example #3

In this example, we will notice how to use the IsError function while working with a bunch of code and how we can test it. So in this example, we will see that expression in the code is an error or not. For example, 10/0 is a dividend error but 0/10 is not an error. For this, follow the below steps:

Step 1: So Again we use the same module for our third example and start by declaring a third subprocedure.

Code:

Sub Example3()

End Sub

VBA IsError Example 3-1

Step 2: Now let us declare two variables, one as an expression while another as an output for the expression.

Code:

Sub Example3()

Dim Expression1
Dim Output As Boolean

End Sub

Declare Two Variables Example 3-2

Step 3: Now let us put a value to the expression.

Code:

Sub Example3()

Dim Expression1
Dim Output As Boolean
Expression1 = 0 / 100

End Sub

VBA IsError Example 3-3

Step 4: Now we will store the output of the expression in the output variable.

Code:

Sub Example3()

Dim Expression1
Dim Output As Boolean
Expression1 = 0 / 100
Output = IsError(Expression1)

End Sub

Output Expression Example 3-4

Step 5: Now we can use the msgbox function to display the result of the output variable.

Code:

Sub Example3()

Dim Expression1
Dim Output As Boolean
Expression1 = 0 / 100
Output = IsError(Expression1)
MsgBox "The expression(0/100) is an error or not : " & Output, vbInformation, "VBA IsError Function"

End Sub

Output variable Example 3-5

Step 6: When we run the above code we will get the following result.

VBA IsError Example 3-6

Explanation of Excel VBA IsError Functions

As we have discussed above that IsError in VBA is an informative function that is used to identify whether a given expression has an error or not. The syntax for the function has one mandatory argument which is the expression that needs to be evaluated.

Also, we can use texts to display in the function to show the relevance as shown in example 3.

Things to Remember

These are the things which we should keep in mind IsError function in VBA and they are as follows,

  1. IsError is an Information function in VBA.
  2. The function has a Boolean value as an output.
  3. The result displayed by the function is either true or false.

Recommended Articles

This is a guide to the VBA IsError. Here we discuss how to Use IsError Function in Excel VBA along with practical examples and downloadable excel template. You can also go through our other suggested articles –

  1. VBA LBound
  2. VBA Solver
  3. VBA Login
  4. VBA Month

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

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

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Web Development & many more.

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

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

EDUCBA

Download VBA IsError Excel Template

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW