Excel VBA Boolean: True, False, and How to Use Them

VBA & macros · Updated November 3, 2026

Excel VBA Boolean: True, False, and How to Use Them

Yes—Excel VBA has a built-in Boolean data type for values that are either True or False. Declare a variable with As Boolean, then use it to store a decision or control an If statement, loop, or other conditional code.

What Boolean means in Excel VBA

A Boolean represents a two-state logical value: true or false. It is useful whenever VBA needs to answer a yes-or-no question, such as whether a cell is blank, whether a number exceeds a limit, or whether a user selected an option. Instead of storing words such as “yes” and “no” in text variables, a Boolean makes the intended kind of information explicit.

For example, a macro might ask whether a sales total is above a target. The comparison itself produces a Boolean result: it is True if the comparison succeeds and False if it does not. Store that result in a Boolean variable if the decision will be used again or if naming it makes the code easier to understand.

  • True means the condition is satisfied.
  • False means the condition is not satisfied.
  • A Boolean is not a place to store arbitrary text, dates, or decimal values.

How VBA represents True and False

In VBA, a Boolean variable occupies two bytes. When a Boolean value is converted to a number, True is represented as -1 and False as 0. This is a detail worth knowing when debugging or working with older code, but it is usually best to treat these values as logical states rather than numbers.

The -1 representation can surprise people who expect true to mean 1. For example, converting a Boolean to an integer does not make True equal to 1. A test such as isReady = 1 is therefore not a reliable way to ask whether a Boolean variable is true. Prefer If isReady Then, or compare it with the Boolean constant True if an explicit comparison is useful.

VBA also defines Not for reversing a Boolean value: Not True is false, and Not False is true. The logical operators And, Or, and Xor can combine conditions. Keep their operands Boolean when you mean logical tests; VBA also allows these operators to work with numeric values as bitwise operators.

Declaring and assigning a Boolean variable

Use the Boolean type in a variable declaration. A comparison can be assigned directly because its result is already true or false. The following small procedure illustrates the pattern:

Sub CheckTarget()
    Dim total As Double
    Dim target As Double
    Dim meetsTarget As Boolean

    ' Example values; replace these with values from your workbook.
    total = 125
    target = 100
    meetsTarget = (total >= target)

    If meetsTarget Then
        MsgBox "Target reached."
    Else
        MsgBox "Target not reached."
    End If
End Sub

The parentheses around the comparison are optional in this assignment, but they make it clear that the comparison result is being stored. Here, meetsTarget becomes True, because 125 is greater than or equal to 100. If the total were 90, it would become False.

As with other VBA variable types, a newly initialized Boolean variable starts as False. Still, setting it deliberately can make the program’s intent clearer, especially when a variable’s value is changed in several places. Adding Option Explicit at the top of a module also helps catch misspelled variable names by requiring declarations.

Boolean values in worksheet cells and VBA

Excel worksheet cells can contain logical values, displayed as TRUE or FALSE. A worksheet formula can also return a logical result, for example as the outcome of a comparison. When VBA reads such a cell through a Range object, the value is commonly held in a Variant whose subtype is Boolean. A VBA Boolean variable, by contrast, can hold only true or false.

That distinction matters because cells can contain many other kinds of values: numbers, text, blanks, and errors. Do not assume that every cell VBA reads can safely be treated as a Boolean. If a cell contains the text “TRUE,” that text is not automatically the same thing as the logical value True in every operation. Decide whether the workbook expects a real logical value or text, then validate or convert accordingly.

For a straightforward logical cell, a test can read naturally as a condition in VBA. If the cell may contain an Excel error, check for that error before trying to compare or convert the value. This avoids a type mismatch interrupting the macro. Likewise, test data imported from a CSV or another system, because imported values that look like TRUE or FALSE may arrive as text.

Using Booleans in conditions and operators

The most common use of a Boolean is controlling code with If...Then...Else. VBA also uses Boolean expressions in loop conditions and in checks involving worksheet values. The clearest conditions usually state the question being asked, rather than converting values to 1 or 0 first.

  • Use If isComplete Then when the variable already contains a Boolean.
  • Use If amount > limit Then when the condition can be written as a direct comparison.
  • Use If hasName And hasDate Then when both Boolean conditions must be true.
  • Use If isWeekend Or isHoliday Then when either Boolean condition is sufficient.
  • Use If Not isComplete Then when the code should run only while a condition is false.

A common VBA difference from languages with short-circuit operators is that And and Or do not skip evaluation of their second operand. Both sides are evaluated. Therefore, do not use an expression like “the object exists And the object’s property is valid” as protection against a missing object; the property access can still be attempted. Use nested If statements when the second check is safe only after the first one passes.

Common Boolean mistakes and how to avoid them

One frequent mistake is confusing the words True and False with text containing those words. Boolean constants are not quoted. Quoted words are strings, and comparisons between strings and Boolean values can produce unexpected results or errors. When a data source supplies text, convert it deliberately after checking the possible inputs.

Another mistake is comparing a Boolean with 1. Because VBA represents true numerically as -1, a numeric comparison to 1 is not equivalent to checking for true. Use the Boolean value directly in an If statement, or compare it to True or False when that improves readability.

Also watch for these issues:

  • Unvalidated cell contents: A cell can contain an error or unexpected text rather than a logical value.
  • Misleading names: Choose names such as isApproved or hasValue so the variable reads like a yes-or-no question.
  • Overcomplicated tests: A Boolean variable does not need to be compared to True in every conditional; If isApproved Then is usually enough.
  • Assuming short-circuit evaluation: Split dependent checks into separate If statements.

A practical macro example with input validation

This example reads a possible amount from cell A1 on Sheet1, checks that it is not an Excel error and is numeric, and writes a message to B1. It then uses a Boolean to hold the result of the limit comparison. The example assumes the worksheet exists and that the amount should accept values VBA recognizes as numeric.

Before running a macro, save a copy of the workbook. VBA macros cannot be undone with Ctrl+Z, and a macro may change workbook contents. On Windows, Alt+F11 opens the Visual Basic Editor; Excel for the web cannot create or run VBA macros.

Sub CheckAmountAgainstLimit()
    Dim sourceValue As Variant
    Dim amount As Double
    Dim limit As Double
    Dim exceedsLimit As Boolean

    ' Read the source cell and reject errors or nonnumeric content.
    sourceValue = ThisWorkbook.Worksheets("Sheet1").Range("A1").Value

    If IsError(sourceValue) Then
        MsgBox "Cell A1 contains an error value."
        Exit Sub
    End If

    If Not IsNumeric(sourceValue) Then
        MsgBox "Cell A1 must contain a number."
        Exit Sub
    End If

    amount = CDbl(sourceValue)
    limit = 100
    exceedsLimit = (amount > limit)

    If exceedsLimit Then
        ThisWorkbook.Worksheets("Sheet1").Range("B1").Value = "Over limit"
    Else
        ThisWorkbook.Worksheets("Sheet1").Range("B1").Value = "Within limit"
    End If
End Sub

If A1 contains 125, the comparison is true and B1 receives “Over limit.” If A1 contains 80, the comparison is false and B1 receives “Within limit.” The validation happens before conversion to Double, so a cell error or nonnumeric entry is reported rather than passed directly into the calculation. Adapt the sheet name, cell addresses, and limit to match the workbook.

Debugging Boolean values

If a branch runs when you did not expect it to, inspect the value at the point where the decision is made. In the Visual Basic Editor, place the cursor on a procedure and use F8 to step through the code on Windows. The Locals window and Watch window can show the current value of a Boolean variable; the Immediate window can also be used to inspect expressions while code is paused.

Check the input as well as the Boolean result. A cell that looks blank may contain a formula returning an empty string, while a cell that appears to say TRUE may contain text rather than a logical value. Also look for later assignments that overwrite the Boolean before the conditional runs. Descriptive variable names and small, separate validation steps make these problems easier to locate.

Frequently Asked Questions

Is Boolean the same as TRUE or FALSE in Excel?
They refer to the same kind of logical state, but context matters. VBA’s Boolean is a variable type, while worksheet cells can display logical values as TRUE or FALSE. Text that spells TRUE or FALSE is a string, not necessarily a logical value.

Can a VBA Boolean be blank?
No. A Boolean variable holds only True or False. A new Boolean variable defaults to False. If you need to distinguish “not answered yet” from both true and false, use a separate status variable or a Variant and handle its possible states carefully.

Why does VBA treat True as -1?
That is VBA’s numeric representation of True; False converts to 0. Most application code should not depend on that numeric detail. Use Boolean comparisons and conditional statements instead of testing a Boolean against 1.

Does VBA have AndAlso or short-circuit And?
No. VBA’s And and Or evaluate both operands. To make the second check conditional on the first, put it in a separate, nested If statement.

Can VBA read TRUE or FALSE from a cell?
Yes, VBA can read a worksheet’s logical value, but cells may also contain text, numbers, blanks, or errors. Check what kind of data the cell actually contains before assigning it to a Boolean or using it in a comparison.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.