Excel VBA: How to Use Not IsError

VBA & macros · Updated November 18, 2026

In Excel VBA, write If Not IsError(value) Then to test whether a value is not an Excel error value. The VBA function IsError returns True for values such as #N/A or #VALUE!, and the VBA operator Not reverses that Boolean result; this is different from using the worksheet formula NOT(ISERROR(...)).

What Not IsError Means in VBA

IsError is a built-in VBA function. It checks whether an expression contains a value of the special Variant/Error type, which is how VBA can represent an Excel error value. For example, reading a cell containing #N/A into a Variant lets VBA inspect that value without treating the cell’s error as a VBA runtime error.

The expression Not IsError(v) is therefore True when v is not an error value, and False when it is. The word “not” does not mean “the cell is not blank,” “the calculation succeeded,” or “the value is numeric.” It reverses only the True or False result from IsError. A blank, text string, number, or date can all pass the not-error test.

Use a Variant variable when you expect to inspect a value that might be an Excel error. A Variant can hold numbers, text, empty values, and Error values. Assigning an Excel error to a restrictive variable type such as Long may instead cause a type mismatch before you get to test it.

How the Test Works with a Cell

For a direct check, read the cell’s value into a Variant and pass that variable to IsError. This makes the value being tested explicit and gives you a convenient place to inspect or reuse it. The following example checks A2 on a worksheet named Sheet1 and reports the outcome in the Immediate window.

Sub CheckOneCell()
    Dim target As Range
    Dim valueToCheck As Variant

    ' Read the cell value; Excel errors are held as Variant/Error values.
    Set target = ThisWorkbook.Worksheets("Sheet1").Range("A2")
    valueToCheck = target.Value2

    If Not IsError(valueToCheck) Then
        Debug.Print "A2 does not contain an Excel error."
    Else
        Debug.Print "A2 contains an Excel error."
    End If
End Sub

To see the Immediate window in the Visual Basic Editor, press Ctrl+G on Windows. On a Mac, use the Visual Basic Editor’s View > Immediate Window command if the window is not already visible. The macro only reads A2 and prints a message; it does not change the worksheet.

You can also pass a cell’s value directly, as in If Not IsError(Range("A2").Value) Then. Assigning it first is often easier to debug, especially when the value comes from a formula, a lookup, or a longer expression. If the cell could contain an error, do not first convert it with CStr, CLng, or another conversion function: that conversion may fail before the error test happens.

Using Not IsError in Conditional Logic

A common reason to use this check is to decide whether a macro should process a value. For example, a report may contain formulas that return valid results for some rows and errors for others. The macro can skip error values, handle them in a separate branch, or write a clear status beside each result.

This example checks the values in A2:A100 and writes a status in the corresponding cell in column B. It deliberately distinguishes errors from other values: a blank cell is not an error, so it will be marked “OK” by this basic test.

Sub MarkErrorValues()
    Dim ws As Worksheet
    Dim sourceCell As Range
    Dim resultValue As Variant

    ' Make a copy of the workbook before running a macro.
    ' Macro changes cannot be undone with Ctrl+Z.
    Set ws = ThisWorkbook.Worksheets("Sheet1")

    For Each sourceCell In ws.Range("A2:A100")
        resultValue = sourceCell.Value2

        If Not IsError(resultValue) Then
            sourceCell.Offset(0, 1).Value = "OK"
        Else
            sourceCell.Offset(0, 1).Value = "Error"
        End If
    Next sourceCell
End Sub

Before running a macro that writes to a workbook, save a copy: VBA changes cannot be reversed with Ctrl+Z. This sample overwrites cells B2:B100, so confirm that those cells are available or change the output range. If you also need to reject blanks, add a separate blank check; do not assume that Not IsError checks for usable content.

Excel Worksheet Formula or VBA?

VBA’s IsError is not the same syntax as the worksheet function ISERROR. In a cell formula, Excel uses function names and parentheses. In VBA, IsError is called in code, and Not is a VBA operator. Both approaches can test for error values, but they run in different places: a worksheet formula recalculates as part of the sheet, while a VBA test runs only when its macro or procedure executes.

With the value to check in A2, enter this worksheet formula in another cell to return TRUE when A2 is not an error and FALSE when it is:

Assumption: the value or formula result being checked is in A2. Formula: =NOT(ISERROR(A2)). If A2 contains #N/A, the result is FALSE; if A2 contains 42, the result is TRUE.

If your goal is to display a fallback instead of an error, IFERROR is usually more direct than testing with ISERROR and then branching. With the calculation in A2, this formula displays an empty string when A2 returns an error and otherwise displays its value:

Assumption: A2 contains the value or formula result to display. Formula: =IFERROR(A2," ") would return a space, not a truly empty string; for a genuinely empty-looking result, use =IFERROR(A2,""). For example, if A2 is #N/A, the result is an empty string; if A2 is 42, the result is 42.

Use IFERROR when the objective is to replace any error result in a worksheet calculation. Use VBA’s Not IsError when code needs to make a decision based on a value it has read. In either case, consider whether hiding an error is appropriate: replacing an error can make a report look clean while concealing a broken reference or unexpected input.

Not IsError Is Not VBA Error Handling

A frequent source of confusion is the difference between an Excel error value and a VBA runtime error. IsError checks a value such as #DIV/0! stored in a cell or returned by a worksheet function. It does not catch every failure that can occur while VBA runs. For example, referencing a missing worksheet or attempting an invalid operation can raise a VBA runtime error rather than give the code a value to inspect.

VBA handles runtime errors with error-handling statements such as On Error GoTo. That mechanism directs execution to an error handler when a runtime error occurs. It is separate from testing a Variant with IsError. A procedure may need both techniques: one to safely handle unexpected VBA failures, and another to decide what to do with an Excel error value that was successfully read from a cell.

There is another important boundary: VBA must evaluate an expression before it can test the result. If evaluating the expression itself raises a runtime error, IsError(expression) cannot prevent that failure. A safer pattern is to read a cell or function result into a Variant, then inspect the stored value. For operations that can raise VBA runtime errors, use appropriate error handling as well.

Common Mistakes and Useful Checks

  • Using a worksheet formula in VBA: NOT(ISERROR(A1)) is worksheet-style syntax, not the normal VBA expression. In VBA, use Not IsError(v), where v is the value you want to test.
  • Assuming not-error means valid: Empty cells, text, zero, and values outside an expected range are not Excel errors. Add the checks your task actually requires, such as a blank test, a numeric test, or a range check.
  • Converting too soon: A conversion such as CDbl(v) may fail if v is an error value. Test with IsError before conversion, and then validate the value’s type and content.
  • Confusing False with an error: A cell containing the Boolean value FALSE is not an Excel error. IsError returns False for it, so Not IsError returns True.
  • Checking a formula’s text instead of its result: Range("A2").Formula returns the formula text, while Range("A2").Value or .Value2 reads the calculated value. Test the result when you want to detect an error displayed by the cell.

For troubleshooting, inspect the Variant in the Visual Basic Editor or print it to the Immediate window, and confirm that the code is reading the intended sheet and cell. Also check whether the cell contains a constant error or a formula that currently evaluates to an error. Both can appear as an Excel error value to VBA, but the way to fix the underlying cause may differ.

Choosing the Right Test

Choose based on what you want the spreadsheet or macro to do. If a worksheet should show a fallback result automatically, use a worksheet function such as IFERROR. If a macro needs to branch, log a result, or skip error cells, use IsError on a Variant holding the cell value. If the concern is a VBA operation that can stop the procedure, use VBA error handling rather than expecting IsError to catch it.

It can also be useful to separate error detection from business rules. For instance, first determine whether a result is an Excel error; then, if it is not, determine whether it is blank, numeric, or within acceptable limits. This gives each condition a clear meaning and makes the code easier to maintain than a single vague “valid” test.

Frequently Asked Questions

Does VBA have an IsError function?
Yes. VBA’s built-in IsError(expression) returns True when the expression evaluates to an Error value. Apply Not to reverse the result when you want to enter a branch only for non-error values.

What does If Not IsError mean?
It means “if this value is not an Excel error value.” It does not guarantee that the value is nonblank, numeric, or suitable for a particular calculation; those conditions need their own tests.

Can I use Not IsError directly on a cell?
Yes. You can test a cell’s value directly, or assign its value to a Variant first. Using a Variant makes the value easier to inspect and helps avoid converting an error before checking it.

What is the difference between IsError and On Error?
IsError checks a value that is already an Excel error value. On Error is VBA’s mechanism for responding to runtime errors raised while code executes. They solve different problems.

How do I show a blank instead of an Excel error?
In a worksheet formula, wrap the calculation in IFERROR(calculation,"") to return an empty string when it produces an error. In VBA, check the returned Variant with IsError and decide what value or action should replace the error.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.