How to use IsError Function in VBA (With Example)


You can use the IsError function in VBA to check if a given cell contains an error value and return TRUE or FALSE as a result.

Here is one common way to use this function in practice:

Sub CheckIsError()

Dim i As Integer
    
For i = 2 To 11
    Range("B" & i).Value = WorksheetFunction.IsError(Range("A" & i))
Next i

End Sub

This particular macro checks if each cell in the range A2:A11 is an error value and returns either TRUE or FALSE in the corresponding cell in the range B2:B11.

The following example shows how to use this syntax in practice.

Example: How to Use IsError Function in VBA

Suppose we have the following column of values in Excel:

Suppose we would like to check if each value in column A is an error value or not.

We can create the following macro to do so:

Sub CheckIsError()

Dim i As Integer
    
For i = 2 To 11
    Range("B" & i).Value = WorksheetFunction.IsError(Range("A" & i))
Next i

End Sub

When we run this macro, we receive the following output:

The values in column B display either TRUE or FALSE to indicate whether or not the corresponding values in column A are error values.

Note that the following values all return TRUE in column B:

  • #DIV/0!
  • #VALUE!
  • #NUM!

All other values return FALSE since they are not error values.

Note: You can find the complete documentation for the VBA IsError function .

x