本帖最后由 adders 于 2012-3-28 19:34 编辑
微软自带的两个例子:
1) 在Worksheets(1)中的A1:A500范围内寻找数值为2的单元格,如找到则改值为5,注意这里用的FindNext来寻找下一个目标:
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 And c.Address <> firstAddress
End If
End With
2) 用FindPrevious来寻找上一个目标(运行前确认在B列至少有两个单元格的文本值是"Phoenix")
Set fc = Worksheets("Sheet1").Columns("B").Find(what:="Phoenix")
MsgBox "第一个Phoenix在单元格 " & fc.Address
Set fc = Worksheets("Sheet1").Columns("B").FindNext(after:=fc)
MsgBox "下一个Phoenix在单元格 " & fc.Address
Set fc = Worksheets("Sheet1").Columns("B").FindPrevious(after:=fc)
MsgBox "上一个Phoenix在单元格 " & fc.Address