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:
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.
More Tutorials
⇠ Back to VBA Function List | What is VBA in Excel
Helpful Links – Developer Tab – Visual Basic Editor – Run a Macro – Personal Macro Workbook – Excel Macro Recorder – VBA Interview Questions – VBA Codes