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
Type
Type: Microsoft.Office.Interop.Excel.XlCellTypeThe cells to include.
Can be one of the following XlCellType values:
xlCellTypeAllFormatConditions. Cells of any format.
xlCellTypeAllValidation. Cells that have validation criteria.
xlCellTypeBlanks. Empty cells.
xlCellTypeComments. Cells that contain notes.
xlCellTypeConstants. Cells that contain constants.
xlCellTypeFormulas. Cells that contain formulas.
xlCellTypeLastCell. The last cell in the used range.
xlCellTypeSameFormatConditions. Cells that have the same format.
xlCellTypeSameValidation. Cells that have the same validation criteria.
xlCellTypeVisible. All visible cells.
Value
Type: System.ObjectIf Type is either xlCellTypeConstants or xlCellTypeFormulas, this argument is used to determine which types of cells to include in the result. These values can be added together to return more than one type. The default is to select all constants or formulas, no matter what the type. Can be one of the following XlSpecialCellsValue values:
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
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.