Name

range.Find(What, [After], [LookIn], [LookAt]), [SearchOrder], [SearchDirection], [MatchCase], [MatchByte], [SearchFormat])

Synopsis

Returns a Range object representing the cell containing the first occurrence of the specified item within the specified range.

Argument

Settings

What

The item to search for. Can be a string or Excel data type.

After

The cell after which the search begins.

LookIn

Specify xlFormulas, xlValues, or xlNotes to limit the search to those types of information.

LookAt

xlPart (default) searches within the cell contents; xlWhole searches whole cells.

SearcbOrder

xlByRows (default) searches one row at a time; xlByColumns searches one column at a time.

SearchDirection

xlNext (default) searches down and to the right; xlPrevious searches up and to the left.

MatchCase

False (default) ignores case; True performs a case-sensitive search.

MatchByte

If double-byte language support is enabled:

  • True matches double-byte characters.

  • False matches double-byte characters to their single-byte equivalents.

SearchFormat

True uses the FindFormat property setting to find cells with specific formatting; False ignores the FindFormat property. Default is False.

The following code selects the first cell in row A that contains the string "Ichiro". Note that the code checks whether the Find method returns Nothing. If you don’t check for Nothing and the Find item isn’t found, the Select method returns an error.

Dim r As Range Dim foundCell As Range ...

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.