我正在努力弄清楚如何找出是否在excel中找不到搜索字符串,我试过了
isnothing(rFoundCell)
但这不起作用,表示找不到方法
而且iserror也不起作用
For rCount = Settings.rowHeaderTempFile + 1 To lRow2
Set rFoundCell = Range("A" & Settings.rowHeader + 1)
Set rFoundCell = ws.Columns(1).Find(What:=ws2.Cells(rCount,
partNumberWs2).Value, After:=rFoundCell,
LookIn:=xlValues, LookAt:=xlPart,
SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False)
If IsError(rFoundCell.Row) Then ' fails here
lRow = lRow + 1
最佳答案
由于rFoundCell
是Nothing
,因此没有.Row
属性。If rFoundCell Is Nothing
似乎更便于处理,但在现实生活中,我不会使用处理,因此依赖过程应基于If Not rFoundCell Is Nothing Then
标准。
For rCount = Settings.rowHeaderTempFile + 1 To lRow2
Set rFoundCell = Range("A" & Settings.rowHeader + 1)
Set rFoundCell = ws.Columns(1).Find(What:=ws2.Cells(rCount,
partNumberWs2).Value, After:=rFoundCell,
LookIn:=xlValues, LookAt:=xlPart,
SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False)
If Not rFoundCell Is Nothing Then
'do stuff
Else
lRow = lRow + 1
End If
关于excel - 在Excel中使用查找方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31285648/