NamedRange.FormulaR1C1 Property

Gets or sets the formula for the object, using R1C1-style notation.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

Object FormulaR1C1 { get; set; }

Property Value

Type: System.Object
The formula for the object, using R1C1-style notation.

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 the 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 FormulaR1C1 property to set the value of the NamedRange to equal the square root of cell A1, as specified using R1C1 notation.

This example is for a document-level customization.


Microsoft.Office.Tools.Excel.NamedRange formulaR1C1Range;
private void SetFormulaR1C1()
{
    formulaR1C1Range = this.Controls.AddNamedRange(
        this.Range["B1", missing], "formulaR1C1Range");
    this.Range["A1", missing].Value2 = 1185921;
    this.formulaR1C1Range.FormulaR1C1 = "=SQRT(R1C1)";
    formulaR1C1Range.Select();
}


Community Additions

ADD
Show: