Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing for NULL

Tags:

excel

vba

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 ??

like image 537
Gary's Student Avatar asked Jun 13 '26 13:06

Gary's Student


1 Answers

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
like image 190
MatthewD Avatar answered Jun 15 '26 07:06

MatthewD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!