次の方法で共有


NamedRange.FindNext(Object) メソッド

定義

Find(Object, Object, Object, Object, Object, XlSearchDirection, Object, Object, 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

検索位置を示すセルです。このセルの次から検索されます。 これは、ユーザー インターフェイスから検索を行う場合のアクティブ セルの位置に相当します。 コントロール内NamedRangeAfter単一のセルである必要があることに注意してください。 検索はこのセルの次から開始されることに注意してください。指定したセル自体が検索されるのは、メソッドがラップしてそのセルに戻ってきたときです。 この引数を指定しなかった場合、検索は NamedRange コントロールの左上隅のセルの後から開始されます。

戻り値

指定した情報が含まれているセルを表す Range オブジェクトを返します。

次のコード例では、 メソッドを Find 使用して、コントロール内の値 Seashell を持つ最初のセルを NamedRange 検索します。 次に、 メソッドと FindPrevious メソッドをFindNext使用して、値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 ソリューションの省略可能なパラメーター」を参照してください。

適用対象