Share via


NamedRange.FormulaR1C1Local Property

Gets or sets the formula for the NamedRange control, using R1C1-style notation 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 FormulaR1C1Local As Object
Object FormulaR1C1Local { get; set; }

Property Value

Type: System.Object
The formula for the NamedRange control, using R1C1-style notation 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 NamedRange control contains a constant, this property returns that constant. If the NamedRange control is empty, this property returns an empty string. If the NamedRange control 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 NamedRange control 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 FormulaR1C1 property to set the value of the NamedRange to equal the square root of cell A1, as specified using R1C1 notation. The formula is localized according to the language of the system it is run on.

This example is for a document-level customization.

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

    Private Sub SetFormulaR1C1Local()
        formulaR1C1LocalRange = Me.Controls.AddNamedRange( _
            Me.Range("B1"), "formulaR1C1LocalRange")
        Me.Range("A1").Value2 = 1185921
        Me.formulaR1C1LocalRange.FormulaR1C1Local = "=SQRT(R1C1)"
        formulaR1C1LocalRange.Select()
    End Sub
Microsoft.Office.Tools.Excel.NamedRange formulaR1C1LocalRange;
private void SetFormulaR1C1Local()
{
    formulaR1C1LocalRange = this.Controls.AddNamedRange(
        this.Range["B1"], "formulaR1C1LocalRange");
    this.Range["A1"].Value2 = 1185921;
    this.formulaR1C1LocalRange.FormulaR1C1Local = "=SQRT(R1C1)";
    formulaR1C1LocalRange.Select();
}

.NET Framework Security

See Also

Reference

NamedRange Interface

Microsoft.Office.Tools.Excel Namespace