在下面的代码中,我试图从预订列表中删除记录(Res_Data)。代码找到正确的记录并删除它;但是,我一直得到"错误424:对象要求"循环上的消息直到测试,我不明白为什么。我没有在任何其他对rngFound的引用中收到错误消息。
Dim rngSearch as Range
Dim rngFound as Range
Dim RecordToDelete as Range
Dim sFirstAddr as String
Set rngSearch = Range("Res_Data")
Set rngFound = rngSearch.Find(What:=dtDate, After:=rngSearch.Cells(1, 1))
If Not rngFound Is Nothing Then
sFirstAddr = rngFound.Address
Do
rngFound = rngSearch.FindNext(rngFound)
If rngSearch.Cells(rngFound.Row, iCageNumCol) = "Y" And rngSearch.Cells(rngFound.Row, BegTime) = sBeginTime Then
Set RecordToDelete = rngSearch.Rows(rngFound.Row)
RecordToDelete.Delete (xlShiftUp)
End If
Loop Until rngFound.Address = sFirstAddr 'Error 424 occurs here
End If
答案 0 :(得分:3)
我猜你还没想过在调试模式下单步调试代码;友情提示:当你遇到像这样的bug时,这通常是你应该做的第一件事。
如果你这样做了,一旦达到rngFound
行,你就会发现Nothing
为Loop Until
,这就是触发你的错误的原因。
那么,为什么它Nothing
而不是之前呢?好吧,因为您之前删除了几行。因此它消失了。无法获得Address
。