Range.Find method (Excel)
Find specific information in the area.
grammar
表达式.Find (What, After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte, SearchFormat)
expression represents Range variable objects.
parameter
name |
Required / Optional |
type of data |
Explanation |
What |
essential |
Variant |
To search for data. It may be a string data type or any Microsoft Excel. |
After |
Optional |
Variant |
To start a cell search thereafter. When searching from the user interface, which corresponds to the position of the active cell. |
LookIn |
Optional |
Variant |
The following may be XlFindLookIn one of the constants: xlFormulas , xlValues , xlComments or xlCommentsThreaded . |
LookAt |
Optional |
Variant |
The following may be XlLookAt one of the constants: xlWhole or xlPart . |
SearchOrder |
Optional |
Variant |
The following may be XlSearchOrder one of the constants: xlByRows or xlByColumns . |
SearchDirection |
Optional |
Direction of the search. |
|
MatchCase |
Optional |
Variant |
If True , the search is case sensitive. The default value is False . |
MatchByte |
Optional |
Variant |
Use only when selected or installed double-byte language support. If True , then double-byte characters match only double-byte characters. If it is False , then the double-byte characters match their equivalent single-byte characters. |
SearchFormat |
Optional |
Variant |
Search format. |
return value
A Range object that represents the first cell where to find this information.
annotation
If no match is found, this method returns Nothing . Find method does not affect the selection or the active cell.
Each time you use this method, it will save LookIn , LookAt , SearchOrder and MatchByte settings. If the next time this method is called values of these parameters are not specified, the value stored is used. Setting these parameters will change the "look" is set **** dialog box, change the "look" Saved values used when setting **** dialog box will change omit the parameter. To avoid problems, please explicitly set these parameters each time you use this method.
Use FindNext and FindPrevious method may repeat the search.
When the search reaches the end of the search area specified, it will go around the region beginning position. To stop this from happening in the wraparound searching, save the address of the cell in the first find, and then test each successive cell address found for this saved address.
To find a cell with a more complex pattern matching, set the For Each ... Next statement with the Like operator is used in combination. For example, the following code search area A1: C5 in all cells in which name begins with letter fonts Cour. When Microsoft Excel to find a match, it will change the font to Times New Roman.
VB |
For Each c In [A1:C5] If c.Font.Name Like "Cour*" Then c.Font.Name = "Times New Roman" End If Next` |
Examples
In this example, the first range A1 a worksheet: to find all the A500 cell values 2, and the value of a cell change these five.
VB |
With Worksheets(1).Range("a1:a500") Set c = .Find(2, lookin:=xlValues) If Not c Is Nothing Then firstAddress = c.Address Do c.Value = 5 Set c = .FindNext(c) Loop While Not c Is Nothing End If End With |