NamedRange.FormulaR1C1 Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the formula for the object, using R1C1-style notation.
public:
property System::Object ^ FormulaR1C1 { System::Object ^ get(); void set(System::Object ^ value); };
public object FormulaR1C1 { get; set; }
member this.FormulaR1C1 : obj with get, set
Public Property FormulaR1C1 As Object
Property Value
The formula for the object, using R1C1-style notation.
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.
This example is for a document-level customization.
Microsoft.Office.Tools.Excel.NamedRange formulaR1C1Range;
private void SetFormulaR1C1()
{
formulaR1C1Range = this.Controls.AddNamedRange(
this.Range["B1"], "formulaR1C1Range");
this.Range["A1"].Value2 = 1185921;
this.formulaR1C1Range.FormulaR1C1 = "=SQRT(R1C1)";
formulaR1C1Range.Select();
}
Private formulaR1C1Range As Microsoft.Office.Tools.Excel.NamedRange
Private Sub SetFormulaR1C1()
formulaR1C1Range = Me.Controls.AddNamedRange( _
Me.Range("B1"), "formulaR1C1Range")
Me.Range("A1").Value2 = 1185921
Me.formulaR1C1Range.FormulaR1C1 = "=SQRT(R1C1)"
formulaR1C1Range.Select()
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 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.