

It’s more efficient within VBA to do it this way than to call the () method. IsBlank = (CStr(rngToCheck.Cells(1).Value2) = vbNullString) Public Function IsBlank(ByRef rngToCheck As Range) As Boolean The upside is we can use COUNTBLANK() to check if a cell is actually blank:Īn easy way to check if a cell is blank from VBA is to call the Range.Value (or Range.Value2) property and compare the result to the constant:ĭebug.Print IsBlank(Sheet1.Range("A4")) 'Falseĭebug.Print IsBlank(Sheet1.Range("B4")) 'Trueĭebug.Print IsBlank(Sheet1.Range("C4")) 'Trueĭebug.Print IsBlank(Sheet1.Range("D4")) 'True COUNTBLANK() will count empty cells, cells with a null string and cells which contain a prefix character. The COUNTBLANK() worksheet function does not behave in a consistent manner with its ISBLANK() counterpart.

It’s worth mentioning that the ISBLANK() worksheet function isn’t available in VBA via the Application.WorksheetFunction class: presumably because Microsoft recognised that its functionality was already covered by VBA.IsEmpty() which is faster to call from VBA. By my own definition, ISBLANK() should’ve been called ISEMPTY(). The ISBLANK() worksheet function and VBA.IsEmpty() give exactly the same results so, unless one considers blank and empty to mean the same thing, they’re obviously inconsistently named. The Range.Value and Range.Value2 properties return a Variant/Empty when the given cell is empty, so the best way to check if a cell is empty in VBA is to use the () function on their output:ĭebug.Print IsEmpty(Sheet1.Range("A4").Value2) 'Falseĭebug.Print IsEmpty(Sheet1.Range("B4").Value2) 'Falseĭebug.Print IsEmpty(Sheet1.Range("C4").Value2) 'Falseĭebug.Print IsEmpty(Sheet1.Range("D4").Value2) 'True Row 3 indicates what is in the corresponding column in row 4. In a worksheet, the best way to check is a cell is empty is to use the ISBLANK() worksheet function: These definitions are just my own – so please don’t take them as gospel – but they’re based on the behaviour of VBA.IsEmpty() and COUNTBLANK().

Two pet peeves of mine are the way the terms and are interchangeably used in Excel.
