自动填充时出现错误 80010108
我正在编写代码,但收到 -2147417848 (80010108) 错误。我知道这是每次它“得到”空单元格时造成的,但我不知道如何修复它,有人可以帮助我吗?代码如下:
Dim i, g As Integer
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
g = 12
For i = 3 To 5000
If Worksheets("Registo_EPI´s").Cells(i, 1).Value = Cells(4, 20).Value Then
Cells(g, 21).Value = Worksheets("Registo_EPI´s").Cells(i, 5).Value
g = g + 1
End If
Next i
End Sub
每当 Cells(i,5) 范围内的单元格为空白时,代码就会崩溃。例如,如果在单元格(3,5)中我有一个数字或日期,如果在单元格(4,5)中我没有任何东西,它就会崩溃。希望你们能帮助我。谢谢
I´m writting a code but i´m getting an -2147417848 (80010108) error. I know that is caused everytime it "gets" a empty cell but i don´t know how to fix it, can someone help me please? Here´s the code
Dim i, g As Integer
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
g = 12
For i = 3 To 5000
If Worksheets("Registo_EPI´s").Cells(i, 1).Value = Cells(4, 20).Value Then
Cells(g, 21).Value = Worksheets("Registo_EPI´s").Cells(i, 5).Value
g = g + 1
End If
Next i
End Sub
Whenever a cell within the range Cells(i,5) is blank, the code crash. Por example if in cell(3,5) i have a number or date and if in cell(4,5) i don´t have anything, its crashes. Hope ou guys can help me. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您的
Worksheet_Change
事件处理程序很可能无意中调用自身,这可能是问题的根源。例如,如果显示的
Worksheet_Change
事件处理程序适用于Sheet1
(因此像Cells(4, 20).Value
这样的非限定引用也引用Sheet1
) 那么当您更改Cells(g, 21)
的值时,Sheet1
的Worksheet_Change
事件处理程序为又打来电话等等 在。您应该使用事件处理程序的
Target
参数来防止这种情况。例如,如果您只对Cells(4, 20)
的更改感兴趣,那么您可以:I think it's quite likely that your
Worksheet_Change
event handler is unintentionally calling itself and that this may be the source of your problem.For example, if the
Worksheet_Change
event handler shown applies toSheet1
(and thus unqualified references likeCells(4, 20).Value
also refer toSheet1
) then when you change the value ofCells(g, 21)
theWorksheet_Change
event handler forSheet1
is called again and so on.You should use the
Target
parameter of the event handler to guard against this. If, for example, you were only interested in changes toCells(4, 20)
then you could have: