Name

[Application.]Evaluate(Name)

Synopsis

Evaluates an expression and returns the result. Evaluate is equivalent to enclosing the expression in square brackets ([ ]).

Argument

Setting

Name

A range address, a named range, or a formula

It is common to use the bracket notation for the Evaluate method since it is shorter. The following code displays various values from the active sheet:

Sub TestEvaluate(  )
    ' Show value of cell A1.
    Debug.Print [a1]
    ' Show total of A1:A3.
    Debug.Print [sum(a1:a3)]
    ' Show table of named ranges
    Dim n As Name, str As String
    Debug.Print "Name", "# w/data", "Address"
    For Each n In Names
        str = "Count(" & n.Name & ")"
        Debug.Print n.Name, Evaluate(str), [n]
    Next
End Sub

Using the bracket notation with a Name object returns the address of the name.

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.