Share via


EVALCELL Function

Takes a reference to a cell that contains a custom function as well as one or more name-value pairs to pass to the custom function as arguments (optional). Returns the calculated result of the custom function given the specified arguments and values.

Syntax

EVALCELL(cellRef,[arg1Name,arg1],[arg2Name,arg2],…)

Parameters

Name Required/Optional Data Type Description
cellRef Required String A reference to the cell that contains the custom function. Cross-sheet references are allowed.
arg1Name Optional String The name of the first argument to be passed to the custom function. Spaces are allowed.
arg1 Optional Varies Value of the arg1 parameter.
arg2Name Optional String The name of the second argument to be passed to the custom function. Spaces are allowed.
arg2 Optional Varies Value of the arg2 parameter.
Aa342315.vs_note(en-us,office.12).gif  Note
You must pass numbered arguments (arg1, arg2, and so forth) as name-value pairs. Passing any given pair is optional, but if you pass an argument name parameter, passing the corresponding argument value parameter is required.

Remarks

The calling cell does not have to specify every argument used by the custom function.

Example
The following example shows how to use the EVALCELL function in conjunction with the ARG function to find the middle value from a set of three values.

In the expression cell, place the following code that defines the custom function:

Visual Basic for Applications
  User.MiddleValue = IF(ARG("A")>ARG("B"),IF(ARG("B")>ARG("C"),ARG("B"),IF(ARG("A")>ARG("C"),ARG("C"),ARG("A"))),IF(ARG("A")>ARG("C"),ARG("A"),IF(ARG("B")>ARG("C"),ARG("C"),ARG("B"))))

In the calling cells, place the following code that calls the custom function:

Visual Basic for Applications
  User.Middle1 = EVALCELL(User.MiddleValue,"A",3,"B",9,"C",5)
User.Middle2 = EVALCELL(User.MiddleValue,"A",12,"B",0,"C",21)