Condividi tramite


Metodo XmlMappedRange.FindPrevious

Continua una ricerca avviata con il metodo Find.

Spazio dei nomi:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

Sintassi

'Dichiarazione
Function FindPrevious ( _
    After As Object _
) As Range
Range FindPrevious(
    Object After
)

Parametri

  • After
    Tipo: System.Object
    Cella prima della quale si desidera eseguire la ricerca.Corrisponde alla posizione della cella attiva quando una ricerca viene eseguita dall'interfaccia utente.Il parametro After deve essere una singola cella nel controllo XmlMappedRange.Tenere presente che la ricerca viene avviata prima di questa cella. La ricerca verrà eseguita nella cella specificata solo quando il metodo completerà il ciclo e tornerà a questa cella.Se questo argomento non è specificato, la ricerca verrà avviata prima della cella superiore sinistra nel controllo XmlMappedRange.

Valore restituito

Tipo: Microsoft.Office.Interop.Excel.Range
Oggetto Range che rappresenta una cella contenente le informazioni specificate.

Note

Trova la cella precedente che soddisfa le condizioni specificate per il metodo Find e restituisce un oggetto Range che rappresenta tale cella.

Questo metodo non influisce sulla selezione o sulla cella attiva.

Parametri facoltativi

Per informazioni sui parametri facoltativi, vedere Parametri facoltativi nelle soluzioni Office.

Esempi

Nell'esempio di codice riportato di seguito il valore di un controllo XmlMappedRange viene impostato su una stringa "Smith". Vengono quindi utilizzati i metodi Find, FindNext e FindPrevious per trovare la prima cella contenente la stringa "Smith".Poiché un controllo XmlMappedRange contiene sempre un'unica cella, la stessa cella viene trovata in ciascun caso.Nell'esempio si presuppone che il foglio di lavoro corrente contenga un controllo XmlMappedRange denominato CustomerLastNameCell.

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

Sicurezza di .NET Framework

Vedere anche

Riferimenti

XmlMappedRange Interfaccia

Spazio dei nomi Microsoft.Office.Tools.Excel