Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
错误时继续下一步不工作VBA_Vba_Excel - Fatal编程技术网

错误时继续下一步不工作VBA

错误时继续下一步不工作VBA,vba,excel,Vba,Excel,我使用Ctrl+F模拟使用宏从工作表中查找特定数字,我添加了错误恢复下一代码,以防它无法找到值,但错误处理不起作用,我得到以下消息 代码如下: Sheets("Not filled").Activate On Error Resume Next Cells.Find(what:=refnumber, After:=ActiveCell, LookIn:=xlFormulas, _ lookat:=xlPart, SearchOrder:=xlByRows, Sear

我使用Ctrl+F模拟使用宏从工作表中查找特定数字,我添加了错误恢复下一代码,以防它无法找到值,但错误处理不起作用,我得到以下消息

代码如下:

Sheets("Not filled").Activate

    On Error Resume Next

    Cells.Find(what:=refnumber, After:=ActiveCell, LookIn:=xlFormulas, _
    lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Activate

有两种可能性:

  • 通过使用
    on Error GoTo 0
    语句,可以重新打开“断开”错误

  • 可以在VBA编辑器选项的错误捕获部分中选择“在所有错误上中断”选项(要选中该选项,请转到VBA编辑器菜单栏上的工具>选项>常规>错误捕获)。 如果选择此选项,则无论应用何种错误处理逻辑,VBA编译器都会中断所有错误


您仍在尝试
。激活
未找到的单元格

Dim fnd As Range, refnumber As Long

refnumber = 123

With Sheets("Not filled")
    .Activate
    On Error Resume Next
    Set fnd = .Cells.Find(what:=refnumber, After:=ActiveCell, LookIn:=xlFormulas, _
        lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)
    On Error GoTo 0
    If Not fnd Is Nothing Then
        fnd.Select
    Else
        MsgBox "Not found :("
    End If
End With

这将尝试将设置为找到的位置。如果找不到任何东西,那么
fnd
var就什么都不是。

如何在VBA中执行?可能是重复的虽然这解释了@Anarach的错误,但肯定不能解释为什么下一次错误恢复时
没有抑制它?@MarkButler确切地说,我的代码昨天起作用了。。完美的今天,它显示出这种奇怪error@Anarach好的,两个问题:1)在
Tools>Options>General>error Trapping
中,错误处理的设置是什么?哇,刚才注意到,我的错误处理程序都没有working@Anarach2)您是否尝试过将错误恢复下一步时的
替换为错误处理程序时的
,并在模块底部添加一个
errorhandler
(例如,带有一个要测试的消息框)?嗨,你知道为什么在电脑重新启动后,错误处理程序会在昨天而不是今天突然工作吗。