XmlMappedRange.FindPrevious(Object) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Continues a search that was begun with the Find(Object, Object, Object, Object, Object, XlSearchDirection, Object, Object, Object) method.
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
Parameters
- After
- Object
The cell before which you want to search. This corresponds to the position of the active cell when a search is done from the user interface. Note that After
must be a single cell in the XmlMappedRange control. Remember that the search begins before this cell; the specified cell is not searched until the method wraps back around to this cell. If this argument is not specified, the search starts before the upper-left cell in the XmlMappedRange control.
Returns
A Range that represents a cell containing the specified information.
Examples
The following code example sets the value of an XmlMappedRange to the string "Smith", and then uses the Find, FindNext, and FindPrevious methods to find the first cell with the string "Smith". Because an XmlMappedRange always contains exactly one cell, the same cell is found in each case. This code example assumes that the current worksheet contains an XmlMappedRange named 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
Remarks
Finds the previous cell that matches the conditions specified for the Find method and returns a Range object that represents that cell.
This method does not affect the selection or the active cell.
Optional Parameters
For information on optional parameters, see Optional Parameters in Office Solutions.