Vba中Find方法使用总结(一)
Sub findNum()
Dim r
As
Range
Set
r = Cells.Find(
'熊猫'
)
If
Not
r
Is
Nothing
Then
r.Interior.Color = vbRed
End
If
End
Sub
Sub findNum1()
Dim r
As
Range
Set
r = Cells.Find(2, lookat:=xlWhole, searchorder:=xlRows)
If
Not
r
Is
Nothing
Then
r.Interior.Color = vbRed
End
If
End
Sub
Sub findNum2()
Dim r
As
Range
Set
r = Cells.Find(2, lookat:=xlWhole, searchorder:=xlRows)
If
Not
r
Is
Nothing
Then
r.Interior.Color = vbRed
End
If
Do While
Not
r
Is
Nothing
Set
r = Cells.Find(2,
after
:=r)
If
Not
r
Is
Nothing
Then
r.Interior.Color = vrRed
End
If
Loop
End
Sub
Sub findNum3()
Dim r
As
Range
Set
r = Cells.Find(2, lookat:=xlWhole, searchorder:=xlRows)
Do While
Not
r
Is
Nothing
r.Interior.Color = vbRed
'程序进入了死循环'
Set
r = Cells.Find(2,
after
:=r)
'判断是不是第一次的单元格'
If r.Address =
'$C$2'
Then
Exit Do
Loop
End
Sub
Sub findNum4()
Dim r
As
Range, s
As
String
Set
r = Cells.Find(2, lookat:=xlWhole, searchorder:=xlRows)
If
Not
r
Is
Nothing
Then
s = r.Address
End
If
Do While
Not
r
Is
Nothing
r.Interior.Color = vbRed
Set
r = Cells.Find(2,
after
:=r)
If r.Address = s
Then
Exit Do
Loop
End
Sub
Sub findNum5()
Dim r
As
Range, s
As
String
Set
r = Cells.Find(2, lookat:=xlWhole, searchorder:=xlRows)
If
Not
r
Is
Nothing
Then
s = r.Address
'do while 循环'
Do
r.Interior.Color = vbRed
Set
r = Cells.Find(2,
after
:=r)
Loop While r.Address <> s
End
If
End
Sub
Sub findNum6()
Dim r
As
Range, s
As
String
Set
r = Cells.Find(2, lookat:=xlWhole, searchorder:=xlRows)
If
Not
r
Is
Nothing
Then
s = r.Address
'do while 循环'
Do
r.Interior.Color = vbRed
Set
r = Cells.Find(2,
after
:=r)
'不断循环,知道r的地址是s时终止'
Loop Until r.Address = s
End
If
End
Sub
Sub findNum7()
Dim r
As
Range, s
As
String
Set
r = Cells.Find(2, lookat:=xlWhole, searchorder:=xlRows)
If
Not
r
Is
Nothing
Then
s = r.Address
'do while 循环'
Do
r.Interior.Color = vbRed
Set
r = Cells.FindNext(r)
'不断循环,知道r的地址是s时终止'
Loop Until r.Address = s
End
If
End
Sub
赞 (0)