NamedRange.FindNext(Object) 方法

定義

public Microsoft.Office.Interop.Excel.Range FindNext (object After);
abstract member FindNext : obj -> Microsoft.Office.Interop.Excel.Range
Public Function FindNext (Optional After As Object) As Range

參數

After
Object

要在此儲存格後開始搜尋。 這個儲存格就是從使用者介面進行搜尋時的現用儲存格位置。 請注意, After 必須是 控件中的 NamedRange 單一單元格。 請記住,搜尋會在這個儲存格後開始,而直到此方法繞回指定儲存格後,才會搜尋這個儲存格。 如果您未指定這個引數,則會從 NamedRange 控制項左上角的儲存格後開始搜尋。

傳回

Range 物件,表示包含指定之資訊的儲存格。

範例

下列程式代碼範例會 Find 使用 方法來尋找控制項中值 Seashell 的第一個 NamedRange 儲存格。 然後,此範例會使用 FindNextFindPrevious 方法來尋找具有 值的 Seashell 下一個單元格,然後返回原始單元格。 最後,此範例會使用 Cut 方法來剪下具有 值 Seashell 的第一個單元格的內容,並將它貼到單元格 B1 中。

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

private void FindValue()
{
    this.Range["A1"].Value2 = "Barnacle";
    this.Range["A2"].Value2 = "Seashell";
    this.Range["A3"].Value2 = "Star Fish";
    this.Range["A4"].Value2 = "Seashell";
    this.Range["A5"].Value2 = "Clam Shell";

    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A1", "A5"],
        "namedRange1");

    // Find the first occurrence of "Seashell".
    Excel.Range Range1 = namedRange1.Find("Seashell",
        Excel.XlLookAt.xlWhole, Excel.XlSearchOrder.xlByColumns,
        Microsoft.Office.Interop.Excel.XlSearchDirection.xlNext,
        false);

    // Find the next occurrence of "Seashell".
    Range1 = namedRange1.FindNext(Range1);

    // Return to the first occurrence of "Seashell".
    Range1 = namedRange1.FindPrevious(Range1);

    // Cut the range with the first "Seashell" and copy it to cell B1.
    Microsoft.Office.Tools.Excel.NamedRange namedRange2 =
        this.Controls.AddNamedRange(Range1, "namedRange2");
    namedRange2.Cut(this.Range["B1"]);
}
Private Sub FindValue()
    Me.Range("A1").Value2 = "Barnacle"
    Me.Range("A2").Value2 = "Seashell"
    Me.Range("A3").Value2 = "Star Fish"
    Me.Range("A4").Value2 = "Seashell"
    Me.Range("A5").Value2 = "Clam Shell"

    Dim namedRange1 As Microsoft.Office.Tools.Excel.NamedRange _
        = Me.Controls.AddNamedRange(Me.Range("A1", "A5"), _
        "namedRange1")

    ' Find the first occurrence of "Seashell".
    Dim Range1 As Excel.Range = namedRange1.Find("Seashell", , , _
        Excel.XlLookAt.xlWhole, Excel.XlSearchOrder.xlByColumns, _
        Microsoft.Office.Interop.Excel.XlSearchDirection.xlNext, _
        False, False, )

    ' Find the next occurrence of "Seashell".
    Range1 = namedRange1.FindNext(Range1)

    ' Return to the first occurrence of "Seashell".
    Range1 = namedRange1.FindPrevious(Range1)

    ' Cut the range with the first "Seashell" and copy it to cell B1.
    Dim namedRange2 As Microsoft.Office.Tools.Excel.NamedRange _
        = Me.Controls.AddNamedRange(Range1, "namedRange2")
    namedRange2.Cut(Me.Range("B1"))
End Sub

備註

尋找符合方法相同條件的 Find 下一個儲存格。

此方法不會影響選取範圍或使用中格。

當搜尋到達指定搜尋範圍的結尾時,它會繞著範圍開頭。 若要在發生這個換行時停止搜尋,請儲存第一個找到儲存格的位址,然後針對這個儲存的位址測試每個連續的找到單元格位址。

選擇性參數

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

適用於