Boolean Data Type in Excel VBA

VBA Boolean Data Type in Excel

Boolean Data Type in Excel VBA explained with syntax and examples. We use the Boolean VBA data type to store logical data. The Boolean VBA data type contains only two states of values either TRUE or FALSE. In other words we can also refer as 1 for True and 0 for False. The default value is False. It is most common frequently used VBA data type to represent True or False. It occupies 2 bytes(16 bits) in memory. We can convert number or numeric data type to boolean data type by using CBool VBA conversion function. Here True and False are keywords in VBA. It doesn’t have literal.

Boolean VBA Data Type Syntax in Excel

Let us see Data Type Boolean Syntax in Excel VBA.

Dim VariableName as Boolean

Where VariableName represents the name of the variable.
and Boolean represents the type of data.

Example on the Boolean VBA Data Type when value is TRUE

Here is an example on the Boolean VBA Data Type in Excel.

Sub VBAF1_Boolean_DataType_True()
    
    'Integer Variable Declaration
    Dim bResult As Boolean
    Dim First_Value As Integer, Second_Value As Integer
        
    'Assign values to variable
    First_Value = 100: Second_Value = 100
    
    If First_Value = Second_Value Then
        MsgBox "Result: " & True, vbInformation, "VBAF1"
    Else
        MsgBox "Result: " & False, vbInformation, "VBAF1"
    End If
        
End Sub

Example on the Boolean VBA Data Type when value is TRUE

Here is an example on the Boolean VBA Data Type in Excel.

Sub VBAF1_Boolean_DataType_False()
    
    'Integer Variable Declaration
    Dim bResult As Boolean
    Dim First_Value As Integer, Second_Value As Integer
        
    'Assign values to variable
    First_Value = 100: Second_Value = 200
    
    If First_Value = Second_Value Then
        MsgBox "Result: " & True, vbInformation, "VBAF1"
    Else
        MsgBox "Result: " & False, vbInformation, "VBAF1"
    End If
        
End Sub

Convert an Expression to Boolean VBA Data Type in Excel

You can convert an expression to Boolean VBA data type using VBA CBool function. Click on the following link to learn about CBool function and complete tutorial and examples.

VBA CBool Function

VBA Data Types

Also read about all other data types. VBA Data Types

Instructions to Run VBA Macro Code or Procedure:

You can refer the following link for the step by step instructions.

Instructions to run VBA Macro Code

Other Useful Resources:

Click on the following links of the useful resources. These helps to learn and gain more knowledge.

VBA Tutorial VBA Functions List VBA Arrays VBA Text Files VBA Tables

VBA Editor Keyboard Shortcut Keys List VBA Interview Questions & Answers Blog

Leave a Comment