FindPrevious Method

Microsoft Office Web Components Visual Basic

expression.FindPrevious(After)

expression    Required. An expression that returns one of the objects in the Applies To list.

After   Optional Variant. The cell before which you want to search. This corresponds to the position of the active cell in the user interface. Note that After must be a single cell in the range. Remember that the search begins before    the active cell; the active cell itself isn’t searched until the FindPrevious method wraps back around to this cell. If this argument isn’t specified, the search starts before the upper-left cell in the range.

Example

This example shows how the FindPrevious method is used with the Find and FindNext methods. Before running this example, make sure that Sheet1 contains at least two occurrences of the word “Redmond” in column B.

Sub Find_Methods()

    Dim rngFoundCell
    Dim rngFindRange

    ' Set a variable to the range to search.
    Set rngFindRange = Spreadsheet1.ActiveSheet.Columns("B")

    ' Find the first occurence of Redmond in column B.
    Set rngFoundCell = rngFindRange.Find("Redmond")

    ' Display the location of the first occurence of Redmond.
    MsgBox "The first occurrence is in cell " & rngFoundCell.Address

    ' Find the next occurence of Redmond in column B.
    Set rngFoundCell = rngFindRange.FindNext(after:=rngFoundCell)

    ' Display the location of the next occurence of Redmond.
    MsgBox "The next occurrence is in cell " & rngFoundCell.Address

    ' Find the previous occurence of Redmond in column B.
    Set rngFoundCell = rngFindRange.FindPrevious(after:=rngFoundCell)

    ' Display the location of the previous occurence of Redmond.
    MsgBox "The previous occurrence is in cell " & rngFoundCell.Address

End Sub