Detect if range is empty

Kano picture Kano · May 30, 2012 · Viewed 196.2k times · Source

I want to check if a range in Excel is empty.

How do I write in VBA code:

If Range("A38":"P38") is empty

Answer

Kano picture Kano · May 30, 2012

Found a solution from the comments I got.

Sub TestIsEmpty()
    If WorksheetFunction.CountA(Range("A38:P38")) = 0 Then
        MsgBox "Empty"
    Else
        MsgBox "Not Empty"
    End If
End Sub