excel - 在Excel中使用查找方法

标签 excel error-handling find vba

我正在努力弄清楚如何找出是否在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

最佳答案

由于rFoundCellNothing,因此没有.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/

相关文章:

excel - 如何根据字体大小将文本从 A 列复制到 B 列

mysql - SQLSTATE[HY000] : General error: 1030

javascript - 在文本中查找关键字

Java 哈希集搜索

arrays - 返回数组中元素的索引 Excel VBA

vba - 按颜色突出显示相交

python - xlsxwriter 正在创建损坏的文件

excel - 在概览页面中显示最后更新的行 - Excel

Spring @ControllerAdvice 与 ErrorController

javascript - jQuery : Accessing error code if image fails to load