How to use the VBA CBOOL Function (Syntax + Example)

HomeVBA Functions LIST (Category Wise)How to use the VBA CBOOL Function (Syntax + Example)

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 VBA CBOOL function, you need to go through the below example where we have written a vba code by using it:

Sub example_CBOOL()
Range("B1").Value = CBool(Range("A1"))
End Sub

In the above example, we have used the value from the 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 which can’t be recognized as a number, VBA will return the run-time 13 error.

Related Functions

CBYTE | CCUR | CDATE | CDBL | CDEC | CHR | CINT | CLNG | CSNG | CSTR | CVAR | FORMATCURRENCY | FORMATDATETIME | FORMATNUMBER | FORMATPERCENT | HEX | OCT | STR | VAL