Excel VBA IsEmpty: Check for Blank Cells
In this article
IsEmpty is a VBA function that returns True when a Variant variable or cell value has never been assigned anything, and False when it holds any value, including an empty-looking string. It is the cleanest way to test whether a cell is truly blank before you write to it, copy from it, or use it in a calculation. The one catch is that IsEmpty only works on a Variant, so you must read the cell's value into a Variant variable first rather than pointing IsEmpty straight at a Range object.
What You'll Need
- Microsoft Excel with the Developer tab enabled (File > Options > Customize Ribbon > check Developer).
- A workbook saved as .xlsm or .xlsb so your macro is retained.
- Basic familiarity with opening the VBA editor (Alt+F11) and inserting a module (Insert > Module).
- Some sample data in a worksheet, including at least one genuinely blank cell and one cell containing a formula that returns an empty string, so you can see the difference.
Step-by-Step
- Open your workbook and press Alt+F11 to open the VBA editor. In the Project Explorer, right-click your workbook name and choose Insert > Module. Menu labels in the VBA editor can vary slightly by Excel version and language, but the Insert menu always contains Module.
- Declare a Variant variable at the top of your procedure. IsEmpty requires a Variant argument; if you pass a String or a Range variable directly you will get a type mismatch or an unexpected result. For example:
Dim v As Variant. - Read the cell's value into that Variant. Use
v = Range("A1").Value. The.Valueproperty returns a Variant, which is exactly what IsEmpty expects. - Test it with
If IsEmpty(v) Then. Put the code you want to run when the cell is blank inside that block, and useElsefor when it is not. - Run a quick test. Put a value in A1 and run the macro; IsEmpty should return False. Clear A1 completely (select it and press Delete) and run again; IsEmpty should return True.
- To check a whole range, loop through it. For example:
For Each c In Range("A1:A10"), thenv = c.Value, thenIf IsEmpty(v) Then. This is the standard pattern for finding the first blank row or skipping empty cells in a report. - Understand what IsEmpty does not catch. A cell containing a formula that returns
""is not empty to IsEmpty, because the cell holds a formula. If you need to treat those as blank, testIf IsEmpty(v) Or v = "" Then, but be aware that comparing an Empty Variant to""can behave unexpectedly, so order the test as shown or useLen(v) = 0after confirming v is not an error. - Handle errors separately. If the cell contains an error value such as #N/A, IsEmpty returns False and any arithmetic on v will fail. Check
IsError(v)before doing calculations. - Save the workbook as .xlsm (File > Save As, choose Excel Macro-Enabled Workbook) so the code survives closing and reopening.
Common Mistakes
- Passing a Range object instead of its value:
IsEmpty(Range("A1"))does not test the cell's contents. Always read.Valueinto a Variant first. - Declaring the variable as String or Double. IsEmpty needs a Variant; other types cannot hold the Empty state.
- Confusing an empty string with an empty cell. A cell with
=""in it is not empty, and IsEmpty will say False. UseLen(Trim(v)) = 0if you want to catch both. - Forgetting that a cell containing a single space is not empty. Trim before testing if users may have typed spaces.
- Using IsEmpty on a cell that contains zero. Zero is a value, so IsEmpty returns False, which is correct but surprises people who expect "blank-looking" to mean empty.
- Testing the whole range object at once, such as
IsEmpty(Range("A1:A10")). That does not tell you whether every cell is blank; loop through the cells instead.
Tips
- For a fast check on a single cell,
IsEmpty(Range("A1").Value)works without a separate variable because.Valuealready returns a Variant. - Use
IsEmptytogether withSpecialCells(xlCellTypeBlanks)when you need to act on every blank in a range at once, but note that SpecialCells only finds truly blank cells, not formula-generated empty strings. - If you are building a data-entry form, test with IsEmpty before writing, so you do not overwrite existing values by accident.
- Keep a small test module with one blank cell, one text cell, one number, one zero, one formula returning "", and one error. Run your checks against all six to confirm your logic before using it on real data.
- Comment your blank-check logic. Future you will thank you for noting whether "blank" means truly empty or just visually empty.
Troubleshooting
- Type mismatch error: You passed a non-Variant to IsEmpty. Change the declaration to
Dim v As Variantand assignv = cell.Value. - IsEmpty always returns False: The cell probably contains a formula returning an empty string, a space, or a zero. Inspect the formula bar and test with
Len(Trim(v)) = 0to see what is really there. - Macro does nothing: Check that the module is in the right workbook and that macros are enabled. If the workbook was saved as .xlsx, the code was discarded on save; re-add it and save as .xlsm.
- Unexpected results after copying cells: Copied blank cells can carry formatting or a formula. Use Paste Special > Values to strip formulas, then retest.
- Error values break your loop: Add
If IsError(v) Thenbefore your IsEmpty test, or useOn Error Resume Nextsparingly and reset it withOn Error GoTo 0.
Frequently Asked Questions
Does IsEmpty work on a cell containing a formula that returns ""?
No. The cell holds a formula, so IsEmpty returns False. Test with Len(v) = 0 if you want to treat formula-generated empty strings as blank.
Can I use IsEmpty directly on a Range?
Not reliably. Read the cell's .Value into a Variant first, or use IsEmpty(Range("A1").Value), which works because .Value is a Variant.
What is the difference between IsEmpty and checking for vbNullString?
IsEmpty tests for the Empty state, meaning nothing has ever been assigned. vbNullString is an empty string, which is a value. A cell that looks blank but contains a formula returning "" is not Empty.
Does IsEmpty detect cells containing only spaces?
No. A space is a character, so the cell is not empty. Use Len(Trim(v)) = 0 to catch whitespace-only entries.
Why does IsEmpty return False for a cell I just cleared?
Either the cell still contains a formula, or you are testing the Range object rather than its value. Clear the cell with Delete, confirm the formula bar is empty, and make sure you assign .Value to a Variant.
Can IsEmpty be used in Excel worksheet formulas?
No. IsEmpty is a VBA function only. In a worksheet, use ISBLANK or COUNTBLANK instead; ISBLANK has the same limitation that formula-generated empty strings are not counted as blank.