Knowledge Point:
Range.Find method Range the range of cells represented by the object class, the search for the cell containing the specified content. Find returns only the results of the first found, 374 Example find this figure: the Range ( "B2 ., G14") Find (374) , returns the Range ( "C4" )
Range.Find(What,After,LookIn,Lookat,SearchOrder,SeachDirection,MatchCase,MatchByte,SeachFormat)
. 9 parameters: What required, rear area 8 parameters, defined as optional parameters (18 increase back).
The What : Meaning, you want to find content; the characteristics of a variant type that can accept numbers, strings, dates, and other VBA data types, supports wildcards (regular expressions, * -? ), In order to achieve fuzzy search . (25 ), ( " Panda" ), (# 3/18/2019 # )
Example 1 to find " Panda" cell ( basic method)
Sub findnum()
Dim i&,j&,d as date
d=time()
For i=1 To 100000
For j=1 To 50
If cells (i, j) = "Panda" Then
cells(i,j).interior.color=vbred
cells(i,j).select
Goto found
End If
next j
next i
Found:
MsgBox "when used Total" & datediff ( "s", d, time ()) & "seconds" 'Back 13 seconds
End Sub
Example 2 to find Panda optimization Example 1 , with a two-dimensional array (Improvement 14 back)
Sub findnum1()
Dim i&,j&,d as date,,arr()
d=time()
arr()=range((1,1),(100000,50))
For i=1 To 100000
For j=1 To 50
If arr (i, j) = "Panda" Then
cells(i,j).interior.color=vbred
cells(i,j).select
Goto Found
End If
next j
next i
Found:
MsgBox "when used Total" & datediff ( "s", d, time ()) & "seconds" 'returns 2 seconds
End Sub
Example 3 to find optimized Panda Example 2 , using Fiund () function, the code is simple, if not the panda, an error occurs (Nothing )
Sub findnum()
Dim d as date, r as range
d=Time()
set r = range (cells (1,1), cells (100000,50)). Find ( "Panda")
If Not r Is Nothing Then ‘如果r不是Nothing,即r is Nothing 为 False,则Not r is Nothing
' Is True , into the branches
r.interior.color=vbred
r.select
MsgBox "when used Total" & Datediff ( "s", d, time ()) & "seconds" 'returns 2 seconds
Else
msgbox " not found "
End If
End Sub