NamedRange.SpecialCells(XlCellType, Object) 方法

定義

取得 Range 物件,表示所有符合指定類型和資料的儲存格。

public Microsoft.Office.Interop.Excel.Range SpecialCells (Microsoft.Office.Interop.Excel.XlCellType Type, object Value);
abstract member SpecialCells : Microsoft.Office.Interop.Excel.XlCellType * obj -> Microsoft.Office.Interop.Excel.Range
Public Function SpecialCells (Type As XlCellType, Optional Value As Object) As Range

參數

Type
XlCellType

要包含的儲存格。可以是下列 XlCellType 其中一個值: xlCellTypeAllFormatConditions。 任何格式的儲存格。 xlCellTypeAllValidation. 含有驗證準則的儲存格。 xlCellTypeBlanks. 空白儲存格。 xlCellTypeComments. 包含備註的儲存格。 xlCellTypeConstants. 包含常數的儲存格。 xlCellTypeFormulas. 包含公式的儲存格。 xlCellTypeLastCell. 使用範圍內的最後一個儲存格。 xlCellTypeSameFormatConditions. 具備相同格式的儲存格。 xlCellTypeSameValidation. 包含相同驗證準則的儲存格。 xlCellTypeVisible. 所有可見的儲存格。

Value
Object

如果 TypexlCellTypeConstantsxlCellTypeFormulas,則會使用這個自變數來判斷要包含在結果中的單元格類型。 這些值會一起加入,以傳回多個類型。 預設是選取所有常數或公式,無論類型為何。 可以是下列 XlSpecialCellsValue 其中一個值: xlErrorsxlLogicalxlNumbersxlTextValues

傳回

Range 物件,表示所有符合指定類型和值的儲存格。

範例

下列程式代碼範例會 NamedRange 建立 ,然後使用 SpecialCells 方法來選取 中 NamedRange最後使用的儲存格。

此範例適用於檔層級自定義。

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();
}
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

備註

選擇性參數

如需選擇性參數的資訊,請參閱 Office 方案中的選擇性參數

適用於