Compartir a través de


XmlMappedRange.FindPrevious(Object) Método

Definición

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

Parámetros

After
Object

Celda antes de la que desea buscar. Corresponde a la posición de la celda activa cuando se realiza una búsqueda desde la interfaz de usuario. Tenga en cuenta que After debe ser una sola celda en el XmlMappedRange control . Recuerde que la búsqueda comienza delante de esta celda; no se busca en la celda especificada hasta que el método vuelve a esta posición. Si no se especifica este argumento, la búsqueda se inicia delante de la celda superior izquierda del control XmlMappedRange.

Devoluciones

Objeto Range que representa una celda que contiene la información especificada.

Ejemplos

En el ejemplo de código siguiente se establece el valor de en XmlMappedRange la cadena "Smith" y, a continuación, se usan los Findmétodos , FindNexty FindPrevious para buscar la primera celda con la cadena "Smith". Dado que un XmlMappedRange elemento siempre contiene exactamente una celda, la misma celda se encuentra en cada caso. En este ejemplo de código se supone que la hoja de cálculo actual contiene un XmlMappedRange denominado CustomerLastNameCell.

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

Comentarios

Busca la celda anterior que coincide con las condiciones especificadas para el Find método y devuelve un Range objeto que representa esa celda.

Este método no afecta a la selección ni a la celda activa.

Parámetros opcionales

Para obtener información sobre los parámetros opcionales, vea Parámetros opcionales en soluciones de Office.

Se aplica a