使用 excel 中的查找方法
Using the find method in excel
我正在努力弄清楚如何确定是否在 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 中找不到搜索字符串,我试过
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