VBA/Excel/Access/Word/Data Type Functions/IsEmpty

Материал из VB Эксперт
Перейти к: навигация, поиск

Test a Variant variable to see whether it has the Empty value

Sub EmptyVar()
    Dim vntName As Variant
    Debug.Print IsEmpty(vntName) "Prints True
    vntName = ""
    Debug.Print IsEmpty(vntName) "Prints False
    vntName = Empty
    Debug.Print IsEmpty(vntName) "Prints True
End Sub

Using the ISEMPTY Function to Check Whether a Cell Is Empty

Sub isemptyDemo()
    LastRow = cells(Rows.count, 1).End(xlUp).row
    For i = 1 To LastRow
        If isempty(cells(i, 1)) Then
            cells(i, 1).resize(1, 4).Interior.ColorIndex = 1
        End If
    Next i
End Sub

Working with Empty and Null

Sub StringVar()
    Dim strName As String
    Debug.Print IsEmpty(strName) "Prints False
    Debug.Print strName = "" "Prints True
End Sub