EXCEL 2010运行时错误'50290'方法“_Evaluate of object'_Worksheet”失败

时间:2014-06-17 10:16:11

标签: excel vba excel-vba runtime-error

然后我双击数据验证的单元格然后尝试从下拉列表中选择我得到错误运行时错误运行时错误'50290'。方法“_Evaluate of object'_Worksheet'失败

Private Sub Worksheet_Change(ByVal Target As Range)

Select Case Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Case Is < 5
        LastRow = 5: CountRow = 0: R = 1
    Case Is > 5
        LastRow = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row: CountRow = LastRow - 4: R = 0
    Case 5
        LastRow = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row: CountRow = LastRow - 4: R = 1
End Select
End Sub

on

Select Case Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
case 1
      msgbox "hello"
end select

运行时错误运行时错误'50290'。应用程序定义或对象定义的错误。

Select Case Cells.Find(What:="*", After:=Range("A1"), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

为什么会这样?

2 个答案:

答案 0 :(得分:1)

尝试使用:

After:=Range("A1")

而不是:

After:=[A1]

编辑:这些都没有在2010年修复它。但是一个简单的错误处理程序似乎解决了第一个更改事件问题(双击然后选择DV下拉列表实际上触发了两个更改事件:

Private Sub Worksheet_Change(ByVal Target As Range)

    On Error GoTo err_handle
    Select Case Cells.Find(What:="*", after:=[A1] SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        Case Is < 5
            lastrow = 5: CountRow = 0: R = 1
        Case Is > 5
            lastrow = Cells.Find(What:="*", after:=[a1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row: CountRow = lastrow - 4: R = 0
        Case 5
            lastrow = Cells.Find(What:="*", after:=[a1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row: CountRow = lastrow - 4: R = 1
    End Select
err_handle:
End Sub

答案 1 :(得分:0)

我在异步模式下使用WinHTTP在电子表格中遇到错误50290,以检查链接/下载数据。根据{{​​3}},当Excel未准备好时脚本尝试写入工作簿时会出现此错误。您可以使用Application.Ready来测试Excel应用程序的就绪状态。

在写入工作簿之前使用此代码在我的脚本中工作:

Do While Not Application.Ready
  DoEvents
Loop