Gary's Student
Gary's Student

Reputation: 96753

Testing for NULL

If I run:

Sub dural()
    MsgBox ActiveSheet.Cells.HasFormula
End Sub

It will display True if all the occupied cells in the worksheet have formulas, and it will display False if none of the occupied cells in the worksheet have formulas.

However if some of the occupied cells have formulas, the documentation

says the property will return Null

How can I craft a MsgBox to display this case ??

Upvotes: 3

Views: 57

Answers (1)

MatthewD
MatthewD

Reputation: 6761

You can use the IsNull function

You can use a function instead of a Sub so you can test where you called it from.

Function dural() As Variant
    dural = ActiveSheet.Cells.HasFormula
    If IsNull(dural) = True Then
        MsgBox "It's null"
    End If
End Function

or leave it as a sub

Sub dural()
    Dim test as Variant
    test= ActiveSheet.Cells.HasFormula
    If IsNull(test) = True Then
        MsgBox "It's null"
    End If
End Sub

Upvotes: 3

Related Questions