Range.Find 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.
Finds specific information in a range and returns a Range object that represents the first cell where that information is found.
public Microsoft.Office.Interop.Excel.Range Find (object What, object After, object LookIn, object LookAt, object SearchOrder, Microsoft.Office.Interop.Excel.XlSearchDirection SearchDirection = Microsoft.Office.Interop.Excel.XlSearchDirection.xlNext, object MatchCase, object MatchByte, object SearchFormat);
Public Function Find (What As Object, Optional After As Object, Optional LookIn As Object, Optional LookAt As Object, Optional SearchOrder As Object, Optional SearchDirection As XlSearchDirection = Microsoft.Office.Interop.Excel.XlSearchDirection.xlNext, Optional MatchCase As Object, Optional MatchByte As Object, Optional SearchFormat As Object) As Range
Parameters
- What
- Object
Required Object. The data to search for. Can be a string or any Microsoft Excel data type.
- After
- Object
Optional Object. The cell after which you want the search to begin. 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 range. Remember that the search begins after
this cell; the specified cell isn’t searched until the method wraps back around to this cell. If you don’t specify this argument, the search starts after the cell in the upper-left corner of the range.
- LookIn
- Object
Optional Object. The type of information.
- SearchOrder
- Object
Optional Object. Can be one of the following XlSearchOrder constants: xlByRows or xlByColumns.
- SearchDirection
- XlSearchDirection
Optional XlSearchDirection. The search direction. Can be one of these XlSearchDirection constants:xlNextdefault
xlPrevious
- MatchCase
- Object
Optional Object. True to make the search case sensitive. The default value is False.
- MatchByte
- Object
Optional Object. Used only if you’ve selected or installed double-byte language support. True to have double-byte characters match only double-byte characters; False to have double-byte characters match their single-byte equivalents.
- SearchFormat
- Object
Optional Object. The search format.
Returns
Remarks
This method returns Nothing if no match is found.
This method doesn’t affect the selection or the active cell.
The settings for LookIn
, LookAt
, SearchOrder
, and MatchByte
are saved each time you use this method. If you don’t specify values for these arguments the next time you call the method, the saved values are used. Setting these arguments changes the settings in the Find dialog box, and changing the settings in the Find dialog box changes the saved values that are used if you omit the arguments. To avoid problems, set these arguments explicitly each time you use this method.
You can use the FindNext(Object) and FindPrevious(Object) methods to repeat the search.
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.
To find cells that match more complicated patterns, use a For Each...Next statement with the Like operator.