Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What Can I Find With Find?

Status
Not open for further replies.

Fallenwing

Programmer
Aug 8, 2003
13
CA
Is there a list that somebody has that explains all the functions of the Find command using VBA macros? Any information would be super. Thanks.
 
Thanks, except for 1 problem. I do not have Visual Basic Help, I have lost my Office CD and can now not install it. Could somebody please copy the data and paste it here in reply to this?
 
Find Method


Finds specific information in a range, and returns a Range object that represents the first cell where that information is found. Returns Nothing if no match is found. Doesn’t affect the selection or the active cell.

For information about using the Find worksheet function in Visual Basic, see Using Worksheet Functions in Visual Basic.

Syntax

expression.Find(What, After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte)

expression Required. An expression that returns a Range object.

What Required Variant. The data to search for. Can be a string or any Microsoft Excel data type.

After Optional Variant. 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 Optional Variant. Can be one of the following XlFindLookIn constants: xlFormulas, xlValues, or xlComments.

LookAt Optional Variant. Can be one of the following XlLookAt constants: xlPart or xlWhole.

SearchOrder Optional Variant. Can be one of the following XlSearchOrder constants: xlByColumns or xlByRows.

SearchDirection Optional Variant. Can be one of the following XlSearchDirection constants: xlNext or xlPrevious. The default constant is xlNext.

MatchCase Optional Variant. True to make the search case sensitive. The default value is False.

MatchByte Optional Variant. 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.

Remarks

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 and FindPrevious 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. For example, the following code searches for all cells in the range A1:C5 that use a font whose name starts with the letters "Cour". When Microsoft Excel finds a match, it changes the font to Times New Roman.

For Each c In [A1:C5]
If c.Font.Name Like "Cour*" Then
c.Font.Name = "Times New Roman"
End If
Next

FindNext Method


Continues a search that was begun with the Find method. Finds the next cell that matches those same conditions and returns a Range object that represents that cell. Doesn’t affect the selection or the active cell.

Syntax

expression.FindNext(After)

expression Required. An expression that returns a Range object.

After Optional Variant. The 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 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 this argument isn’t specified, the search starts after the cell in the upper-left corner of the range.

Remarks

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.


FindPrevious Method


Continues a search that was begun with the Find method. Finds the previous cell that matches those same conditions and returns a Range object that represents that cell. Doesn’t affect the selection or the active cell.

Syntax

expression.FindPrevious(After)

expression Required. An expression that returns a Range object.

After Optional Variant. 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 range. Remember that the search begins before this cell; the specified cell isn’t searched until the method wraps back around to this cell. If this argument isn’t specified, the search starts before the upper- left cell in the range.

Remarks

When the search reaches the beginning of the specified search range, it wraps around to the end 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.

Replace Method


Finds and replaces characters in cells within the specified range. Using this method doesn’t change either the selection or the active cell.

For information about using the Replace worksheet function in Visual Basic, see Using Worksheet Functions in Visual Basic.

Syntax

expression.Replace(What, Replacement, LookAt, SearchOrder, MatchCase, MatchByte)

expression Required. An expression that returns a Range object.

What Required String. The string you want Microsoft Excel to search for.

Replacement Required String. The replacement string.

LookAt Optional Variant. Can be one of the following XlLookAt constants: xlWhole or xlPart.

SearchOrder Optional Variant. Can be one of the following XlSearchOrder constants: xlByRows or xlByColumns.

MatchCase Optional Variant. True to make the search case sensitive.

MatchByte Optional Variant. You can use this argument only if you’ve selected or installed double-byte language support in Microsoft Excel. True to have double-byte characters match only double-byte characters. False to have double-byte characters match their single-byte equivalents.

Remarks

The settings for LookAt, SearchOrder, MatchCase, 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.

The replace method always returns True


:)

Skip,
Skip@TheOfficeExperts.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top