XmlMappedRange.FindNext 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 FindNext ( _
After As Object _
) As Range
Range FindNext(
Object After
)
Parameters
After
Type: System.ObjectThe cell after 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 after 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 after the cell in the upper-left corner of the XmlMappedRange control.
Return Value
Type: Range
A Range that represents a cell containing the specified information.
Remarks
Finds the next cell that matches the conditions specified for the Find method and returns a Range that represents that cell.
This method does not affect the selection or the active cell.
When the search reaches the end of the specified search range, it wraps around to the beginning of the range. To stop a search when this wraparound occurs, save the address of the first found cell, and then test each successive found-cell address against this saved address.
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.