range.find 91运行错误
为了在表格中找到匹配的字符我用了range.find()方法,但是由于我是循环多个sheets进行匹配,有的sheets里面没有匹配的字符,所有find就为空了。就报91错误。。下面是部分实现代码求大神分析。
For i = 1 To sheetsNum
Sheets(sheetsNum + 1 - i).Activate
MsgBox (Sheets(sheetsNum + 1 - i).Name)
Set findOK = range.Find(p1, LookIn:=xlValues)
If Not findOK Is Nothing Then range = findOK
、sheetsNum代表表格中sheets的数量,报错的是Set findOK = range.Find(p1, LookIn:=xlValues),有人说加一个If Not findOK Is Nothing Then range = findOK判断过程就不会出现find为空时的错误,但我加了也没管用。。。
VBA range.find()
[解决办法]
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