Can I use the `CVErr` function in VBA to detect and handle potential division by zero errors?

Question

Grade: Education Subject: Support
Can I use the `CVErr` function in VBA to detect and handle potential division by zero errors?
Asked by:
93 Viewed 93 Answers

Answer (93)

Best Answer
(291)
Yes, `CVErr(expression)` returns `True` if the expression results in any Excel error, including `#DIV/0!`. You can use it within an `If` statement to check for the error before it propagates. Example: `If CVErr(numerator / denominator) Then result = 0 Else result = numerator / denominator`.