XmlMappedRange.Find メソッド

定義

XmlMappedRange コントロールで特定の情報を検索し、その情報が見つかった最初のセルを表す Range を返します。

public Microsoft.Office.Interop.Excel.Range Find (object What, object After, object LookIn, object LookAt, object SearchOrder, Microsoft.Office.Interop.Excel.XlSearchDirection SearchDirection = Microsoft.Office.Interop.Excel.XlSearchDirection.xlNext, object MatchCase, object MatchByte, object SearchFormat);
abstract member Find : obj * obj * obj * obj * obj * Microsoft.Office.Interop.Excel.XlSearchDirection * obj * obj * obj -> Microsoft.Office.Interop.Excel.Range
Public Function Find (What As Object, Optional After As Object, Optional LookIn As Object, Optional LookAt As Object, Optional SearchOrder As Object, Optional SearchDirection As XlSearchDirection = Microsoft.Office.Interop.Excel.XlSearchDirection.xlNext, Optional MatchCase As Object, Optional MatchByte As Object, Optional SearchFormat As Object) As Range

パラメーター

What
Object

検索するデータです。 文字列、または Microsoft Office Excel の任意のデータ型を使用できます。

After
Object

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

LookIn
Object

情報の種類です。

LookAt
Object

XlLookAt 値 (xlWhole または xlPart) のどちらかです。

SearchOrder
Object

XlSearchOrder 値 (xlByRows または xlByColumns) のどちらかです。

SearchDirection
XlSearchDirection

検索の方向。または のいずれかの値 xlNextxlPreviousXlSearchDirection指定できます。

MatchCase
Object

検索で大文字と小文字を区別する場合は true です。 既定値は false です。

MatchByte
Object

2 バイト言語サポートを選択またはインストールした場合のみ使用します。 2 バイト文字を 2 バイト文字にのみ一致させる場合は true。2 バイト文字を、等価な 1 バイト文字に一致させる場合は false

SearchFormat
Object

検索形式です。

戻り値

指定した情報が見つかった最初のセルを表す Range を返します。

次のコード例では、 のXmlMappedRange値を文字列 "Smith" に設定し、、、および FindPrevious メソッドをFindFindNext使用して、文字列 "Smith" を持つ最初のセルを検索します。 には XmlMappedRange 常に 1 つのセルが含まれているため、各ケースで同じセルが見つかります。 このコード例では、現在のワークシートに という名前CustomerLastNameCellの が含まれていることをXmlMappedRange前提としています。

private void FindSmith()
{
    this.CustomerLastNameCell.Value2 = "Smith";

    // Use Find to get the range with "Smith".
    Excel.Range range1 = this.CustomerLastNameCell.Find("Smith",
        Excel.XlSearchDirection.xlNext);
    string address1 = range1.get_Address(missing, missing,
        Excel.XlReferenceStyle.xlA1);
    MessageBox.Show("Find method found the range: " + address1);

    // Use FindNext to get the range with "Smith".
    Excel.Range range2 = this.CustomerLastNameCell.FindNext(range1);
    string address2 = range2.get_Address(
        Excel.XlReferenceStyle.xlA1);
    MessageBox.Show("FindNext method found the range: " + address2);

    // Use FindPrevious to get the range with "Smith".
    Excel.Range range3 = this.CustomerLastNameCell.FindPrevious(range2);
    string address3 = range3.get_Address(
        Excel.XlReferenceStyle.xlA1);
    MessageBox.Show("FindPrevious method found the range: " + address3);
}
Private Sub FindSmith()
    Me.CustomerLastNameCell.Value2 = "Smith"

    ' Use Find to get the range with "Smith".
    Dim range1 As Excel.Range = Me.CustomerLastNameCell.Find( _
        "Smith", SearchDirection:=Excel.XlSearchDirection.xlNext)
    Dim address1 As String = range1.Address(ReferenceStyle:=Excel.XlReferenceStyle.xlA1)
    MsgBox("Find method found the range: " & address1)

    ' Use FindNext to get the range with "Smith".
    Dim range2 As Excel.Range = Me.CustomerLastNameCell.FindNext(range1)
    Dim address2 As String = range2.Address(ReferenceStyle:=Excel.XlReferenceStyle.xlA1)
    MsgBox("FindNext method found the range: " & address2)

    ' Use FindPrevious to get the range with "Smith".
    Dim range3 As Excel.Range = Me.CustomerLastNameCell.FindPrevious(range2)
    Dim address3 As String = range3.Address(ReferenceStyle:=Excel.XlReferenceStyle.xlA1)
    MsgBox("FindPrevious method found the range: " & address3)
End Sub

注釈

一致するものが見つからない場合、このメソッドは を返 null します。

このメソッドは、選択範囲やアクティブ セルには影響しません。

LookAtSearchOrderMatchByteLookIn設定は、このメソッドを使用するたびに保存されます。 これらの引数に値を指定しない場合、次回 メソッドを呼び出すと、保存された値が使用されます。 これらの引数を設定すると、[検索] ダイアログ ボックスの設定が変更され、[検索] ダイアログ ボックスの設定を変更すると、引数を省略した場合に使用される保存された値が変更されます。 問題を回避するには、このメソッドを使用するたびにこれらの引数を明示的に設定します。

メソッドと FindPrevious メソッドをMicrosoft.Office.Interop.Excel.Range.FindNext*使用して、検索を繰り返すことができます。

適用対象