VBA Check IF a Cell is Empty + Multiple Cells

Last Updated: June 22, 2023
puneet-gogia-excel-champs

- Written by Puneet

To check if a cell is empty you can use VBA’s ISEMPTY function. In this function, you need to use the range object to specify the cell that you want to check, and it returns true if that cell is empty, otherwise false. You can use a message box or use a cell to get the result.

Use VBA to Check IF a Cell is Empty

  1. Start with the function name “IsEmpty”.
  2. Specify the cell that you want to check.
  3. Use a message box or a cell to get the result value.
  4. In the end, run the code.
MsgBox IsEmpty(Range("A1"))
use vba to check if a cell is empty

Check IF Multiple Cells Empty

If you want to check and count the empty cells from a range when you need to loop through each cell in the range.

Sub vba_check_empty_cells()

Dim i As Long
Dim c As Long
Dim myRange As Range
Dim myCell As Range

Set myRange = Range("A1:A10")

For Each myCell In myRange
    c = c + 1   
    If IsEmpty(myCell) Then
        i = i + 1
    End If   
Next myCell   

MsgBox _
"There are total " & i & " empty cell(s) out of " & c & "."

End Sub

The above code loops through each cell in the range A1:A10 and check each cell one by one using the ISEMPTY function if it’s empty or not.

And for each empty cell it takes a count, and in the end, shows a message box with the total number of cells and empty cells out of that.

Use the following code if you want to highlight empty cells as well.

Dim i As Long
Dim c As Long
Dim myRange As Range
Dim myCell As Range

Set myRange = Range("A1:A10")

For Each myCell In myRange '
    c = c + 1
    If IsEmpty(myCell) Then
        myCell.Interior.Color = RGB(255, 87, 87)
        i = i + 1
    End If
Next myCell

MsgBox _
"There are total " & i & " empty cell(s) out of " & c & "."