Learn Excel - Simplify Life with Excel Concepts

Excel CBool Function (VBA)

Cbool Function VBA Code

How to use the CBool Function (VBA)

This Excel tutorial explains how to use the Excel CBool function with syntax and examples using VBA.

SUMMARY:

The Excel VBA CBool function evaluates an expression, and returns the result as a Boolean data type.

For example,

  • The VBA Code CBool(1=2) would return False.
  • The VBA Code CBool(1=1) would return True.

PURPOSE:

To convert an expression to a Boolean result.

RETURN VALUE:

Boolean (True or False).

SYNTAX:

CBool( expression )

ARGUMENTS:

The CBool function syntax has the following arguments:

  • expression: Required. The expression to evaluate and convert to a boolean.
    • Any valid string or numeric expression
    • The CBool function is often used to return the result of a logical expression
    • The "expression" can be any valid string or numeric expression.

REMARKS:

  • The CBool function can only be used in VBA code in Microsoft Excel.
  • If the expression evaluates to a nonzero value, CBool returns True, otherwise, it returns False.
  • This function will convert any numerical value into a boolean value.
  • If the expression passed to the function is outside the range of the data type being converted to, an error occurs.
  • Numeric non-zero values are converted to True.
  • The strings "True" and "False" are converted to True and False respectively.

Useful Links: Link 1Link 2Link 3Link 4