Skip to main content
A newer version of this page is available. .

How to: Create a Named Range of Cells

  • 2 minutes to read

Tip

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E4938.

This example demonstrates how to create a named range of cells in a worksheet. You can do this in one of the following ways.

Note

When specifying a name for a cell or range of cells, follow the rules listed in the Defined Names document.

Worksheet worksheet = workbook.Worksheets[0];

// Create a range.
Range rangeB3D6 = worksheet.Range["B3:D6"];
// Specify the name for the created range.
rangeB3D6.Name = "rangeB3D6";

// Create a new defined name with the specifed range name and absolute reference.
DefinedName definedName = worksheet.DefinedNames.Add("rangeB17D20", "Sheet1!$B$17:$D$20");
// Create a range using the specified defined name.
Range B17D20 = worksheet.Range[definedName.Name];