wpf-16337-controls-and-libraries-spreadsheet-examples-cells-how-to-create-a-named-range-of-cells.md
Tip
A complete sample project is available in the DevExpress Code Examples database at https://supportcenter.devexpress.com/ticket/details/e4938/wpf-spreadsheetcontrol-api-part-1.
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.
CellRange rangeB3D6 = worksheet.Range["B3:D6"];
// Specify the name for the created range.
rangeB3D6.Name = "rangeB3D6";
// Create a new defined name with the specified range name and absolute reference.
DefinedName definedName = worksheet.DefinedNames.Add("rangeB17D20", "Sheet1!$B$17:$D$20");
// Create a range using the specified defined name.
CellRange B17D20 = worksheet.Range[definedName.Name];
Dim worksheet As Worksheet = workbook.Worksheets(0)
' Create a range.
Dim rangeB3D6 As CellRange = 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.
Dim definedName As DefinedName = worksheet.DefinedNames.Add("rangeB17D20", "Sheet1!$B$17:$D$20")
' Create a range using the specified defined name.
Dim B17D20 As CellRange = worksheet.Range(definedName.Name)