XmlMappedRange.FindPrevious Method
Continues a search that was begun with the Find method.
Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)
Syntax
'Declaration
Function FindPrevious ( _
After As Object _
) As Range
Range FindPrevious(
Object After
)
Parameters
After
Type: System.ObjectThe 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.
Return Value
Type: Microsoft.Office.Interop.Excel.Range
A Range that represents a cell containing the specified information.
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.
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 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 Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.