Export (0) Print
Expand All
Expand Minimize

NamedRange.FormulaLocal Property

Gets or sets the formula for the NamedRange control, using A1-style references in the language of the user.

Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel (in microsoft.office.tools.excel.dll)

public Object FormulaLocal { get; set; }

Property Value

The formula for the NamedRange control, using A1-style references in the language of the user.

Using this property on a NamedRange control that contains multiple cells will cause an exception to be thrown.

If the cell contains a constant, this property returns that constant. If the cell is empty, this property returns an empty string. If the cell contains a formula, this property returns the formula as a string, in the same format in which it would be displayed in the formula bar (including the equal sign).

If you set the value or formula of a cell to a date, Microsoft Office Excel checks to see whether that cell is already formatted with one of the date or time number formats. If not, the number format is changed to the default short date number format.

If the range is a one-dimensional or two-dimensional range, you can set the formula to an array of the same dimensions. Similarly, you can put the formula into an array.

The following code example creates a NamedRange and then uses the FormulaLocal property to set the value of the NamedRange to equal the sum of the values of cells A1 and A2. The formula is localized according to the language of the system it is run on.

Microsoft.Office.Tools.Excel.NamedRange formulaLocalRange;
private void SetFormulaLocal()
{
    formulaLocalRange = this.Controls.AddNamedRange(
        this.Range["B1", missing], "formualLocalRange");
    this.Range["A1", "A2"].Value2 = 2222;
    this.formulaLocalRange.FormulaLocal = "=Sum(A1+A2)";
}

Show:
© 2015 Microsoft