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)

Syntax

'Declaration
Property FormulaLocal As Object
    Get
    Set
Object FormulaLocal { get; set; }

Property Value

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

Remarks

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.

Examples

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.

This example is for a document-level customization.

Private formulaLocalRange As Microsoft.Office.Tools.Excel.NamedRange

Private Sub SetFormulaLocal()
    formulaLocalRange = Me.Controls.AddNamedRange( _
        Me.Range("B1"), "formualLocalRange")
    Me.Range("A1", "A2").Value2 = 2222
    Me.formulaLocalRange.FormulaLocal = "=Sum(A1+A2)"
End Sub
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)";
}

.NET Framework Security

See Also

Reference

NamedRange Interface

Microsoft.Office.Tools.Excel Namespace