VBA CVERR Function (Syntax + Example)

Last Updated: June 22, 2023
puneet-gogia-excel-champs

- Written by Puneet

The VBA CVERR function is listed under the vba error handling category of VBA functions. When you use it in a VBA code, it returns an error data type according to the code you specify. In simple words, with CVERR you can get an error type in the result. Check out these error codes from here.

Syntax

CVErr(Expression)

Arguments

  • Expression: The error code for which you want to know the error data type.

Example

To practically understand how to use the VBA CVERR function, you need to go through the below example where we have written a vba code by using it:

example-vba-cveer-function

In the above code, we have used CVERR and the IF condition with it to test, where it checks if the value in cell A2 is zero or not, and if it is, we have supplied error code 11 (11 is the error data type which represents a division by zero) to the function to return the error data type.

Notes

  • If the argument that you have defined as an error code is not an error code and other than a number, VBA will return the run-time 13 error.
  • And if the argument which you have defined is a number but not an error code, VBA will return a run-time 5 error.