Partager via


NamedRange.SpecialCells Method

Gets a Microsoft.Office.Interop.Excel.Range object that represents all the cells that match the specified type and value.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

Syntax

'Declaration
Function SpecialCells ( _
    Type As XlCellType, _
    Value As Object _
) As Range
Range SpecialCells(
    XlCellType Type,
    Object Value
)

Parameters

Return Value

Type: Microsoft.Office.Interop.Excel.Range
A Microsoft.Office.Interop.Excel.Range object that represents all the cells that match the specified type and value.

Remarks

Optional Parameters

For information on optional parameters, see Optional Parameters in Office Solutions.

Examples

The following code example creates a NamedRange and then uses the SpecialCells method to select the last used cell in the NamedRange.

This example is for a document-level customization.

Private Sub SelectLastCell()
        Dim namedRange1 As Microsoft.Office.Tools.Excel.NamedRange _
            = Me.Controls.AddNamedRange(Me.Range("A1", "A20"), _
            "namedRange1")
        namedRange1.Value2 = 100

        Dim lastCell As Excel.Range = _
            namedRange1.SpecialCells( _
            Excel.XlCellType.xlCellTypeLastCell, )
        lastCell.Select()
    End Sub
private void SelectLastCell()
{
    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A1", "A20"],
        "namedRange1");
    namedRange1.Value2 = 100;

    Excel.Range lastCell = namedRange1.SpecialCells(
        Excel.XlCellType.xlCellTypeLastCell);
    lastCell.Select();
}

.NET Framework Security

See Also

Reference

NamedRange Interface

Microsoft.Office.Tools.Excel Namespace