WallStreetMojo

WallStreetMojo

WallStreetMojo

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

VBA ISERROR

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

Excel VBA ISERROR Function

VBA IsError the function name itself sums up the functionality. This function will identify whether the value we have supplied is an error value or not. If the supplied value or range reference value is an error value then we will get the result as “TRUE”, if the value is not an error value then we will get the result as “FALSE”.

Syntax

IsError Syntax

The expression is nothing but the value we are testing or the cell reference value or formula expression. And as you can see, the result will be “Boolean.”

Examples

You can download this VBA ISERROR Excel Template here – VBA ISERROR Excel Template

Example #1

We will see a simple example to find whether the value is an error or not. For example, we have below value in cell A1.

Example 1.1 (Excel Data)

We will test whether this value is an error value or not.

  • Start the macro code.

Code:

Sub IsError_Example1()

End Sub

Example 1.2

  • Declare a variable to store the cell A1 value.

Code:

Sub IsError_Example1()

    Dim ExpValue As Variant

End Sub

Example 1.3

  • Now assign the value of cell A1 to this variable in VBA.

Code:

Sub IsError_Example1()

    Dim ExpValue As Variant
    ExpValue = Range("A1").Value

End Sub

Example 1.4

  • Now test whether this variable value is an error or not.

Code:

Sub IsError_Example1()

    Dim ExpValue As Variant
    ExpValue = Range("A1").Value

    IsError (ExpValue)

End Sub

Excel VBA ISERROR - Example 1.5

  • Enclose this result in a message box in VBA.

Code:

Sub IsError_Example1()

    Dim ExpValue As Variant
    ExpValue = Range("A1").Value

    MsgBox IsError(ExpValue)

End Sub

Excel VBA ISERROR - Example 1.6

Ok, let’s run the code and see the result of the ISERROR function.

ISERROR Output 1

The result is TRUE because the value in cell A1 is #DIV/0! which is the division error.

Popular Course in this category
Sale
All in One Excel VBA Bundle (35 Courses with Projects)
4.9 (1,353 ratings)
35+ Courses | 120+ Hours | Full Lifetime Access | Certificate of Completion
View Course

Now we will change the value of the cell A1 to “Hello.”

VBA ISERROR - Example 1.7

Now run the code and see the result.

Excel VBA ISERROR Output 2

So, the result is FALSE now because the value in cell A1 is not the error value.

So, first, we need to understand what are the error types and why they occur in excel worksheet. Below are the detailed error values and explanations.

  • #DIV/0: This error occurs mainly because when we try to divide the number by zero. This error is called “Division by Zero.”
  • #N/A: When you try to fetch the data from different tables, and if the no value found, then we will get this error, and this error is called “Not Available.”
  • #NAME?: If excel not able to recognize the formula or name, then we will get this error.
  • #NULL!: When you specify a space character in between the cell references instead of a comma.
  • #NUM!: The numerical value supplied to the data isn’t a valid one.
  • #VALUE!: When you reference the cell values for mathematical calculations, and if the number format is not correct, we will get this error.
  • #REF!: If the cell is a formula, it has cell references, and if that referenced cell is deleted, then we will get this reference error.

Example #2

Now, look at the below data set.

Example 2 (Excel Data)

We need to identify what are the error values from this list and store the result, either TRUE or FALSE, in the next column.

Since we need to test more than one cell, we need to include this in loops; the below code will identify the error values.

Code:

Sub IsError_Example2()

    Dim k As Integer

    For k = 2 To 12
        Cells(k, 4).Value = IsError(Cells(k, 3).Value)
    Next k

End Sub

Example 2 (VBA Code)

When you run this code, we will get the below result in column 4.

ISERROR Output 3

Wherever TRUE is there, that value is an error value.

Things to Remember

  • ISERROR returns the Boolean type result, i.e., either TRUE or FALSE.
  • It is available as a worksheet function as well as a VBA function.
  • It is useful as part of large VBA projects.
  • It recognizes only pre-determined error values (Read error type).

Recommended Articles

This has been a guide to VBA ISERROR. Here we discuss how the excel VBA ISERROR function identifies whether the value we have supplied is an error value or not with examples. You can learn more about VBA functions from the following articles –

  • VBA IsDate Function
  • IFERROR in VBA
  • VBA On Error GoTo
  • VBA 1004 Error Example
  • VBA Double
0 Shares
Share
Tweet
Share
All in One Excel VBA Bundle (35 Courses with Projects)
  • 35+ Courses
  • 120+ 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

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?

WallStreetMojo

Download VBA ISERROR Excel Template

Special Offer - All in One Financial Analyst Bundle (250+ Courses, 40+ Projects) View More