A newer version of this page is available. Switch to the current version.
How to: Create a Named Range of Cells
- 2 minutes to read
- Use the Worksheet.Range property to access a cell range (see the How to: Access a Range of Cells document for details). Then, specify the range name via the Range.Name property of the created Range object.
- Use the DefinedNameCollection.Add method to add a new defined name for the specified range to the worksheet’s collection of defined names (Worksheet.DefinedNames). Then, use the Worksheet.Range property and pass the DefinedName.Name property value of the previously created defined name object.
When specifying a name for a cell or range of cells, follow the rules listed in the Defined Names document.
using DevExpress.Spreadsheet; // ... IWorkbook workbook = spreadsheetControl1.Document; Worksheet worksheet = workbook.Worksheets; // Create a range. Range rangeA2A4 = worksheet.Range["A2:A4"]; // Specify the name for the created range. rangeA2A4.Name = "rangeA2A4"; // Create a new defined name with the specifed range name and absolute reference. DefinedName definedName = worksheet.DefinedNames.Add("rangeC2D3", "Sheet1!$C$2:$D$3"); // Create a range using the specified defined name. Range rangeC2D3 = worksheet.Range[definedName.Name];