I am using the Ctrl+F simulation using Macros for find a particular number from a sheet, I have added the On error resume next code in case it fails to find the value but the error handling is not working , I am getting the following message.
我正在使用Ctrl+F模拟,使用宏从表中查找一个特定的数字,我已经添加了On error resume next代码,以防它找不到值但错误处理不起作用,我将得到以下消息。
Here is the code:
这是代码:
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
2 个解决方案
#1
1
You are still trying to .Activate
the (NOT) found cell.
您仍在尝试激活(未)找到的单元格。
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
This attempts to Set
a Range object to the found location. If nothing was located, the fnd
var is nothing.
尝试将Range对象设置为已找到的位置。如果没有找到任何东西,那么fnd var就不是什么。
#2
0
There are two possibilities:
有两种可能性:
-
Breaking on errors could have been turned back on, by using
On Error GoTo 0
statement.通过使用on Error GoTo 0语句,可以重新打开错误。
-
Breaking on All Errors option can be selected in Error Trapping section of VBA editor option (to check it go to Tools > Options > General > Error Trapping on VBA editor menu bar). If this option is selected, VBA compiler breaks on all errors no matter what error handling logic is applied.
可以在VBA编辑器选项的错误捕获部分中选择“破坏所有错误”选项(要检查它到工具>选项>在VBA编辑器菜单栏上的常规>错误捕获)。如果选择此选项,无论应用何种错误处理逻辑,VBA编译器都会对所有错误进行中断。
#1
1
You are still trying to .Activate
the (NOT) found cell.
您仍在尝试激活(未)找到的单元格。
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
This attempts to Set
a Range object to the found location. If nothing was located, the fnd
var is nothing.
尝试将Range对象设置为已找到的位置。如果没有找到任何东西,那么fnd var就不是什么。
#2
0
There are two possibilities:
有两种可能性:
-
Breaking on errors could have been turned back on, by using
On Error GoTo 0
statement.通过使用on Error GoTo 0语句,可以重新打开错误。
-
Breaking on All Errors option can be selected in Error Trapping section of VBA editor option (to check it go to Tools > Options > General > Error Trapping on VBA editor menu bar). If this option is selected, VBA compiler breaks on all errors no matter what error handling logic is applied.
可以在VBA编辑器选项的错误捕获部分中选择“破坏所有错误”选项(要检查它到工具>选项>在VBA编辑器菜单栏上的常规>错误捕获)。如果选择此选项,无论应用何种错误处理逻辑,VBA编译器都会对所有错误进行中断。