HasFormula Property

Microsoft Office Web Components Visual Basic

True if all cells in the range contain formulas, False if none contain formulas, and Null if some cells contain formulas and others do not. Read-only Variant. Use the IsNull function to determine if the return value is Null.

expression.HasFormula

expression    Required. An expression that returns a Range object.

Example

This example recalculates the active worksheet if any cell in the currently selected range contains a formula.

Sub CalcIfSelectionHasFormulas()
    Dim vntHasFormula
    Dim rngCurrent
    
    Set rngCurrent = Spreadsheet1.Selection
    
    ' Set a variable to the HasFormula property
    ' for the current selection.    
    vntHasFormula = rngCurrent.HasFormula
    
    If IsNull(vntHasFormula) Then
    
        ' Calculate the active worksheet if the
        ' selection contains one or more formulas.
        Spreadsheet1.ActiveSheet.Calculate
        
    ElseIf vntHasFormula Then
    
        ' Calculate the active worksheet if all
        ' selected cells contain a formula.
        Spreadsheet1.ActiveSheet.Calculate
    End If
End Sub