vba EXCEL 2010 运行时错误 '50290' 对象 '_Worksheet' 的方法“_Evaluate”失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24261203/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 03:28:52  来源:igfitidea点击:

EXCEL 2010 Run-time error '50290' Method "_Evaluate' of object'_Worksheet' failed

excelvbaexcel-vbaruntime-error

提问by user3748026

Then i double click on cell with data validation and then try to select from dropdown I get error Runtime error Run-time error '50290'. Method "_Evaluate' of object'_Worksheet' failed

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

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

Runtime error Run-time error '50290'. Application-defined or object-defined error.

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

on

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

Why this happens?

为什么会发生这种情况?

回答by Rory

Try using:

尝试使用:

After:=Range("A1")

rather than:

而不是:

After:=[A1]

Edit: neither of these fixes it in 2010. However a simple error handler seems to resolve the first change event issue (the double-click then selecting the DV dropdown actually fires two change events:

编辑:这些都没有在 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

回答by robartsd

I ran into error 50290 in a spreadsheet using WinHTTP in async mode to check links/download data. According to this www.pcreview.co.uk thread, this error comes up when a script tries to write to a workbook when Excel is not ready. You can test the ready state of the Excel application with Application.Ready.

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

Using this code before writing to the workbook worked in my script:

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

Do While Not Application.Ready
  DoEvents
Loop