HOWTO · VBA

How to Check if a Cell Is Empty in Microsoft Excel VBA

This article explains the ways to check if a cell is empty in Microsoft Excel VBA.

On this page

For a genuinely blank worksheet cell, IsEmpty(Range("A1").Value) is the usual VBA check. A formula that displays no characters still has a formula, so use a string comparison or Len when that result should count as blank. Choose the check that matches what your macro needs to detect.

Ways to Check if a Cell Is Empty

Excel cells can hold constants, formulas, or no value. VBA’s Empty is a Variant state, while Null is a distinct value; neither is interchangeable with a formula that evaluates to "". The examples use A2 after it has been cleared. When your workbook uses formulas, decide whether a formula returning "" should count as blank before choosing a method.

Method 1: The IsEmpty Function

IsEmpty returns True when its argument is an uninitialized Variant. A cell with a constant, a formula, or an error value is not an uninitialized Variant, even if a formula displays nothing. The following syntax illustration checks A2; place it in a standard VBA module and run CheckA2 after clearing A2. VBA cannot be executed by the configured example runtime, so this procedure is unexecuted and has no claimed runtime output. Copy these lines into a standard VBA module:

Sub CheckA2()
    If IsEmpty(Range("A2").Value) Then
        MsgBox "A2 is blank"
    Else
        MsgBox "A2 contains a value or formula"
    End If
End Sub

For the stated cleared-cell setup, the If branch is designed to show A2 is blank. A formula in A2 that returns "" takes the Else branch because the cell still contains a formula. You can also pass the Range object, but .Value makes the value being checked explicit.

The illustration below shows a separate populated-cell example: A1 contains the text “Not empty,” while the rows beneath it are blank. For that setup, IsEmpty(Range("A1").Value) returns False because A1 contains text.

Worksheet with A1 containing “Not empty” and blank rows below

IsBlank is an Excel worksheet function name, not a VBA function you can call directly. If you need worksheet-function behavior, use Application.WorksheetFunction where supported, or use a VBA check whose semantics fit the task.

Method 2: Compare With vbNullString

vbNullString is a VBA constant representing a zero-length string; it does not hold the Null value. If Range("A2").Value = vbNullString Then compares the cell value with that string. This recognizes a cleared cell and a formula result of "" as blank, so it answers a different question from IsEmpty. For a formula-aware check that handles errors before comparing, use this procedure instead of CheckA2. VBA cannot be executed by the configured example runtime, so the procedure is unexecuted and has no claimed runtime output. Copy these lines into the same standard VBA module:

Sub CheckA2ForBlankResult()
    If IsError(Range("A2").Value) Then
        MsgBox "A2 contains an error"
    ElseIf Range("A2").Value = vbNullString Then
        MsgBox "A2 is blank or its formula returns an empty string"
    Else
        MsgBox "A2 contains a nonempty value"
    End If
End Sub

Method 3: Compare With an Empty String

Comparing with the literal "" has similar string-comparison behavior: If Range("A2").Value = "" Then. It is useful when both a cleared cell and a formula result of "" should follow the same branch. It does not prove that the cell has no formula or that it is truly blank. Check HasFormula separately if the distinction matters, and test IsError in a separate branch before comparing when errors are possible.

Method 4: The Len Function

Len returns the number of characters in a string representation. The condition If Len(Range("A2").Value) = 0 Then is useful when the question is whether the result has zero characters. It can also match a formula result of ""; it does not distinguish that from a cleared cell. Numeric values have a nonzero string length, while Len on an error value is not a safe general check. Use IsError first when errors are possible.

Method 5: The Count and Counta Functions

Count counts numeric cells in a range; CountA counts cells containing data, including text and formulas. For one cell, Application.WorksheetFunction.Count(Range("A2")) = 0 means it has no numeric value, not necessarily that it is blank. CountA(Range("A2")) = 0 detects a cleared cell, but a formula returning "" is still counted because the cell contains a formula. For a multi-cell range, these functions return counts, so compare with the range size only if your goal is to determine whether every cell meets the chosen criterion.

Method 6: The IsNull Function

IsNull tests whether a Variant contains the VBA Null value, often used to represent missing or unknown data. An ordinary blank worksheet cell is not Null, so IsNull(Range("A2").Value) is not a general blank-cell check and returns False for the cleared-cell example. Use it only when your VBA data source can actually supply Null and that is the state you want to identify.

Conclusion

For a cell with no value, use IsEmpty on its .Value. If a formula returning "" should also follow the blank branch, compare with vbNullString or "", or check Len against zero. Count asks whether numeric data is present; CountA asks whether the cell contains data or a formula. IsNull is for the distinct VBA Null value. Guard comparisons and Len when worksheet errors are possible, and use HasFormula when formula presence matters.