Excel VBA Isempty

There are two ways to “excel vba isempty”: the quick way you copy and the durable way you understand. This page gives you both. The exact Excel answer is above; below, we build the small mental model that makes the fix stick, so the next variation of the same problem solves itself.

Exact answer

In Excel: Use If IsEmpty(ws.Range("A1").Value) Then for a truly untouched cell, or If ws.Range("A1").Value = "" Then when a formula returning "" should also count as blank. Excel for the web cannot create, run, or edit VBA macros. Open the workbook in the Excel desktop app to work with macros.

On this page8

VBA macro: Check Whether a Cell Is Empty

Scroll code horizontally to see more
Sub CountEmptyCells()
    Dim ws As Worksheet
    Dim cell As Range
    Dim emptyCount As Long
    Set ws = ActiveSheet
    For Each cell In ws.Range("A1:A20")
        If IsEmpty(cell.Value) Then
            emptyCount = emptyCount + 1
            cell.Interior.Color = RGB(255, 235, 156)
        End If
    Next cell
    If emptyCount = 0 Then
        MsgBox "No empty cells in A1:A20.", vbInformation
    Else
        MsgBox emptyCount & " empty cell(s) highlighted.", vbExclamation
    End If
End Sub

IsEmpty is True only for a genuinely untouched cell. A cell holding =IF(A1="","",A1) looks blank on screen but contains a formula, so IsEmpty returns False while .Value = "" returns True — the two tests answer different questions.

How to run this macro

  1. Press Alt + F11 to open the VBA editor.
  2. Insert > Module.
  3. Paste the code above.
  4. Press F5, or close the editor and run it from Developer > Macros.
  5. Save the file as .xlsm so the macro is kept.
▤Annotated stepsExcel
1

Decide which blank you mean: never-typed-into, or displaying nothing.

2

For never-typed-into, test If IsEmpty(cell.Value) Then.

3

For displaying nothing, test If cell.Value = "" Then, or equivalently If Len(cell.Value) = 0 Then.

4

For a whole range or row, use If Application.WorksheetFunction.CountA(rng) = 0 Then instead of looping.

5

Test against real data containing at least one formula-blank, because that is the case where the two tests disagree.

Ctrl+CthenCtrl+Shift+V⌘+Cthen⌘+Ctrl+VPaste values · WindowsMac

What this does

Excel has more than one kind of blank, which is why this question has more than one answer. A cell that has never been typed into is Empty — IsEmpty returns True and it holds no value at all. A cell containing a formula that evaluates to "" looks identical on screen but is not empty: it holds a formula, so IsEmpty returns False while comparing .Value to "" returns True. A cell holding a single space is empty to neither test. Which test to use follows from which of those you mean. For a whole range there is a fourth option: Application.WorksheetFunction.CountA(rng) = 0 answers "is every cell in this range blank" in one call, without a loop, and is what row-deletion macros should use rather than testing one column and hoping. Len(cell.Value) = 0 is a common shorthand that behaves like the "" comparison and reads a little more clearly for text. A macro runs in the desktop app's VBA environment, not in the cell grid: the workbook has to be saved in a macro-enabled format such as .xlsm to keep the code, and your macro security settings — or a file that arrived from the internet — can block it until you trust it. Excel for the web cannot run VBA at all. The difference between a quick fix and a sheet you can trust is the extra minute you spend validating “excel vba isempty”. Start on a copy or a tiny sample, keep the affected cells visible, and compare the result with the outcome you expected before you touch the real workbook. When this is a ribbon command, the selection matters more than the button: confirm the range, apply the command, then spot-check the output before saving. The point is a workflow that saves repeating the same clicks every week, but the practical win is that someone else can open the file and understand what happened without asking you.

A worked example

You need to flag gaps in an ID column before importing the sheet. Sub CountEmptyCells() walks A1:A20, tests each cell with IsEmpty, shades the blanks pale amber and reports the total. Run it against a column where one cell holds =IF(B1="","",B1) and that cell will not be highlighted — correctly, because it is not empty, it merely displays nothing. If your import treats both as missing, swap the test to If cell.Value = "" Then and it will catch both. For the different question of whether an entire row is blank, drop the loop: If Application.WorksheetFunction.CountA(ws.Rows(i)) = 0 Then covers all 16,384 columns at once, which is why it is the right guard before deleting a row. Nearly every data-cleaning macro turns on this test, and getting it wrong is quiet rather than loud: rows are skipped or deleted based on a definition of "blank" that does not match the one in your head. Choosing deliberately between IsEmpty, the "" comparison and CountA is what makes the result predictable. If the macro will be shared, add a comment at the top saying what it changes and which sheet it expects, and keep the workbook as .xlsm — saving it as .xlsx removes the code.

In Google Sheets

Google Sheets does not run VBA. A macro written for Excel has to be rewritten in Google Apps Script (Extensions ▸ Apps Script), and an .xlsm file converted to Sheets keeps its cells but drops the code. Nothing on this page is behind a login or a download: the exact answer is at the top, and the detail below it is there for when you need it. That is the whole promise here — the answer first, and just enough context to make it stick. For “excel vba isempty”, the checks are about the environment as much as the code: desktop Excel with macros enabled for this file, a macro-enabled workbook and a saved copy to fall back on. Run it once on test data, compare the result with what the code says it does, and only then run it on the real sheet.

Common mistakes

  • Using IsEmpty on a formula cell and concluding the sheet is populated. IsEmpty asks whether the cell holds anything at all, and a formula counts — even one that shows nothing.
  • Passing a multi-cell range to IsEmpty. It evaluates the first cell only and quietly reports on that, giving a confident wrong answer about the rest. CountA is the range-level test.
  • Missing cells that contain a single space. Neither test treats " " as blank; if imported data might carry one, compare Trim(cell.Value) = "" instead.
  • Testing only column A before deleting a row. A row can have an empty A and real data in D — CountA over the whole row is the check that prevents destroying it.
  • Confusing VBA's IsEmpty with the worksheet ISBLANK function. They are different tools with similar names; from VBA the equivalent is Application.WorksheetFunction.CountBlank or a direct IsEmpty test.

Frequently asked questions

What is the difference between IsEmpty and Value = ""?

IsEmpty is True only for a cell with nothing in it at all. Value = "" is also True for a cell holding a formula that returns an empty string. Pick based on whether a formula-blank should count.

How do I check whether an entire range is blank?

If Application.WorksheetFunction.CountA(ws.Range("A1:D100")) = 0 Then. CountA counts non-empty cells, so zero means every cell in the range is blank, and it needs no loop.

Is there an ISBLANK in VBA?

Not by that name. IsEmpty is the closest VBA equivalent; the worksheet function is reachable as Application.WorksheetFunction.CountBlank(rng) if you specifically want Excel's own definition.

Why does a cell that looks empty fail my test?

It almost certainly holds a formula returning "", or a single space left by an import. Check with Len(cell.Formula) and Len(cell.Value) — if they differ, a formula is present.