Share via


XmlMappedRange.FindPrevious 方法

繼續以 Find 方法開始的搜尋。

命名空間:  Microsoft.Office.Tools.Excel
組件:  Microsoft.Office.Tools.Excel (在 Microsoft.Office.Tools.Excel.dll 中)

語法

'宣告
Function FindPrevious ( _
    After As Object _
) As Range
Range FindPrevious(
    Object After
)

參數

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

傳回值

型別:Microsoft.Office.Interop.Excel.Range
Range ,表示包含指定資訊的儲存格。

備註

找到上一個符合 Find 方法指定條件的儲存格,並傳回表示該儲存格的 Range

這個方法不會影響選取範圍或現用儲存格。

選擇性參數

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

範例

下列程式碼範例將 XmlMappedRange 的值設定為字串 "Smith",然後使用 FindFindNext 和 FindPrevious 方法,找到第一個含 "Smith" 字串的儲存格。 因為 XmlMappedRange 必定只會包含一個儲存格,所以在每次搜尋時,都會找到同一個儲存格。 這個程式碼範例假設目前工作表包含名為 CustomerLastNameCell 的 XmlMappedRange

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

.NET Framework 安全性

請參閱

參考

XmlMappedRange 介面

Microsoft.Office.Tools.Excel 命名空間