Export (0) Print
Expand All
Expand Minimize

NamedRange.Cells Property

Gets a Microsoft.Office.Interop.Excel.Range that represents the cells in the NamedRange control.

Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel (in microsoft.office.tools.excel.dll)

public Range Cells { get; }

Property Value

A Microsoft.Office.Interop.Excel.Range that represents the cells in the NamedRange control.

The following code example creates a NamedRange and colors the interior green. It then displays a series of messages that show how many cells, columns, and rows are in the NamedRange.

Microsoft.Office.Tools.Excel.NamedRange compositeRange;
private void DisplayRangeComposition()
{
    compositeRange = this.Controls.AddNamedRange(
        this.Range["B2", "E5"], "compositeRange");
    compositeRange.Cells.Interior.Color = 0xFF00;
    MessageBox.Show("The range has " + compositeRange.Count + 
        " cells.");
    MessageBox.Show("The range has " + 
        compositeRange.Columns.Count + " columns.");
    MessageBox.Show("The range has " + 
        compositeRange.Rows.Count + " rows.");
}

Show:
© 2014 Microsoft