VBA CBOOL Function (Syntax + Example)

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

- Written by Puneet

The VBA CBOOL function is listed under the data type conversion category of VBA functions. When you use it in a VBA code, it converts an expression into a boolean value. In simple words, it converts all the non-zero values to TRUE and zeroes to FALSE and returns that in the result. You can also use it in a logical test.

Syntax

CBool(Expression)

Arguments

  • Expression: The expression is the number that you want to convert into a boolean value

Example

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

example-vba-cbool-function
Sub example_CBOOL()
Range("B1").Value = CBool(Range("A1"))
End Sub

In the above example, we have used the value from cell A1 where we have a number (3) and then we have used the CBOOL function to convert that value into a boolean and it has returned TRUE in the result.

Notes

  • If the value specified is a value other than a number or a number that can’t be recognized as a number, VBA will return the run-time 13 error.