Back to Devexpress

How to: Use Names in Formulas

officefileapi-12199-spreadsheet-document-api-examples-formulas-how-to-use-names-in-formulas.md

latest1.9 KB
Original Source

How to: Use Names in Formulas

  • Sep 19, 2023

This example demonstrates how to use a named cell range in a formula. In some cases, it can be useful to name individual cells and cell ranges to make it easier to understand what information they contain.

View Example

csharp
// Access the "A2:C5" range of cells in the worksheet.
CellRange range = worksheet.Range["A2:C5"];

// Specify the name for the created range.
range.Name = "myRange";

// Create a formula that sums up the values of all cells included in the specified named range.
worksheet.Cells["F3"].Formula = "= SUM(myRange)";
vb
' Access the "A2:C5" range of cells in the worksheet.
Dim range As CellRange = worksheet.Range("A2:C5")

' Specify the name for the created range.
range.Name = "myRange"

' Create a formula that sums up the values of all cells included in the specified named range.
worksheet.Cells("F3").Formula = "= SUM(myRange)"

The image below shows a named cell range, and the result returned by the formula using this range (the workbook is opened in Microsoft® Excel®).

See Also

How to: Create a Named Range of Cells

How to: Create Named Formulas

Defined Names