Share via


NamedRange.FormulaLocal Property

Definition

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

public:
 property System::Object ^ FormulaLocal { System::Object ^ get(); void set(System::Object ^ value); };
public object FormulaLocal { get; set; }
member this.FormulaLocal : obj with get, set
Public Property FormulaLocal As Object

Property Value

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

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.

Microsoft.Office.Tools.Excel.NamedRange formulaLocalRange;
private void SetFormulaLocal()
{
    formulaLocalRange = this.Controls.AddNamedRange(
        this.Range["B1"], "formualLocalRange");
    this.Range["A1", "A2"].Value2 = 2222;
    this.formulaLocalRange.FormulaLocal = "=Sum(A1+A2)";
}
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

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.

Applies to