NamedRange.Calculate Method
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.
Calculates the values of cells in a NamedRange control.
public:
System::Object ^ Calculate();
public object Calculate ();
abstract member Calculate : unit -> obj
Public Function Calculate () As Object
Returns
Examples
The following code example sets the Formula property of a NamedRange control to calculate the sum of cells A1 through A5, uses the FormulaHidden property to hide the formula, and then calls the Calculate method to calculate the sum of the cells and place the sum in cell A6.
This example is for a document-level customization.
private void CalculateRange()
{
Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
this.Controls.AddNamedRange(this.Range["A1", "A5"],
"namedRange1");
Microsoft.Office.Tools.Excel.NamedRange namedRange2 =
this.Controls.AddNamedRange(this.Range["A6"],
"namedRange2");
namedRange1.Value2 = 5;
namedRange2.Formula = "=SUM(A1:A5)";
namedRange2.FormulaHidden = true;
namedRange2.Calculate();
}
Private Sub CalculateRange()
Dim namedRange1 As Microsoft.Office.Tools.Excel.NamedRange _
= Me.Controls.AddNamedRange(Me.Range("A1", "A5"), _
"namedRange1")
Dim namedRange2 As Microsoft.Office.Tools.Excel.NamedRange _
= Me.Controls.AddNamedRange(Me.Range("A6"), _
"namedRange2")
namedRange1.Value2 = 5
namedRange2.Formula = "=SUM(A1:A5)"
namedRange2.FormulaHidden = True
namedRange2.Calculate()
End Sub