我是普通的VBA用户,无法弄清楚为什么我会收到错误。
以下是代码:
Set cell = AA.Sheets(sc).Columns("E").Find(Name, LookAt:=xlWhole)
If Not cell Is Nothing Then
FirstAddress = cell.Address
Do
s = Application.WorksheetFunction.Match(AA.Sheets(av).Rows(3).Find(AA.Sheets(sc).Range("F" & cell.Row)), AA.Sheets(av).Range("A3:NC3"), 0)
p = Application.WorksheetFunction.Match(AA.Sheets(av).Rows(3).Find(AA.Sheets(sc).Range("G" & cell.Row)), AA.Sheets(av).Range("A3:NC3"), 0)
Set cell = AA.Sheets(sc).Columns("E").FindNext(cell)
Loop While cell.Address <> FirstAddress 'ERROR ON THIS LINE
End If
Set cell = Nothing
我得到一个对象变量或者没有设置块变量错误。在第一次运行低谷之后,'cell'正在返回'Nothing',即使应该还有2次传递。如果我删除's ='和'p ='行,它就会正确完成。我需要那些我正在做的事情。
我该如何解决这个问题?谢谢!
答案 0 :(得分:0)
您有此错误,因为's'和'p'行使用Excel的'Find'对象。应用程序只有一个“查找”实例。您在第一行初始化它,然后使用“FindNext”。只有在中间不使用“查找”对象时才有效。