VBA CBool function

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

CBool Function Description

The VBA CBool function converts an expression (variable) to Boolean data type.


The syntax for the CBool function in VBA is:

CBool( expression )


An expression / variable that is to be converted to Boolean data type.

Other Notes

If the expression / variable can’t be converted to Boolean the function with return Error code 13: Type mismatch.
The CBool function will convert:

  • Numbers – Non-zero value will be converted to True, zero values are converted to False.
  • Strings – “true” string will convert to True, “false” will be converted to False.

Example usage

The CBool function can be used in VBA code. Let’s look at some VBA CBool function examples:

CBool 1 
'Result: True

CBool 0 
'Result: False

CBool 21 
'Result: True

CBool "true"
'Result: True

CBool "false"
'Result: False

Dim x, y
x = 1: y = 10
CBool x=y
'Result: False
x = 22: y = 22
CBool x = y
'Result: True

Simply the best place to learn Excel VBA