Version

SetValuesFormula(String,String) Method

Sets the formula which specifies the accepted values.
Syntax
'Declaration
 
Public Overloads Sub SetValuesFormula( _
   ByVal valuesFormula As String, _
   ByVal address As String _
) 
public void SetValuesFormula( 
   string valuesFormula,
   string address
)

Parameters

valuesFormula
The formula which provides the accepted values for the rule.
address
The address of the cell or region that serves as the basis for relative references, or null to use the top-left cell of the worksheet.
Exceptions
ExceptionDescription
System.ArgumentNullExceptionOccurs when valuesFormula is null and the rule is currently applied to a Worksheet.
FormulaParseExceptionOccurs when valuesFormula is not a valid formula.
System.ArgumentException Occurs when the specified value contains something other than a string or reference.
System.ArgumentException Occurs when the specified value contains a region reference which has more than one row and column.
System.ArgumentExceptionOccurs when address is not a valid cell or regions address.
Remarks

The formula must be a string containing the list of accepted values or a reference to a cell or region in the same Workbook which contains the accepted values.

If a formula equaling a string is specified, it must be a string literal and it cannot be concatenated. For example, an acceptable formula would be ="A,B,C". If one of the values must contain a double quote ("), the character should be repeated in the list, like so: ="A,""B"",C". This will allow the values A, "B", and C. The separator between values must be a comma (,), unless the decimal separator for the current culture is a comma, in which case the separator must be a semicolon (;).

If a formula equaling one or more references is specified, it must be a reference to a single cell or region in the same Workbook. Union, intersection, and range operators are not allowed. An acceptable formula might be =$A$1 or =Sheet2!$A$1:$A$5. In addition to a single cell or region, a named reference can also be used, but only if it refers to a single cell or region. If a region is specified, or a named reference that refers to a region, the region must consist of a single row or column. A formula that equals an error value is also allowed, but will cause the cell to not accept any values and the drop down to be empty, so it is not very useful.

The address passed in is only needed if relative addresses are used in the the formula. When the data validation rule is applied to cells or regions, the references in the formula used by each individual cell will be shifted by the offset of the cell to the passed in address. For example, consider the formula specified is =B1 and the specified address is A1. If the data validation rule is then applied to the A5 cell, the formula is will use is =B5. However, if the references in the formula are absolute, such as =$B$1, the same formula will be applied regardless of the specified address.

address can be any valid cell or region reference on a worksheet. If a region address is specified, the top-left cell or the region is used. The cell or region specified does not need to have the data validation rule applied to it. Any reference is allowed.

The cell reference mode with which to parse address will be assumed to be A1, unless the data validation rule is applied to a worksheet which is in a workbook, in which case the Workbook.CellReferenceMode will be used.

Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also