如果值符合if
语句标准,我正在尝试遍历范围并搜索另一个范围。如果搜索失败,我想要一个msgbox出现。我虽然坚持如何设置搜索失败的标准。
Dim r2 As Range
For Each r2 In WorkRng2
If r2.Offset(0, 1).Value <> 0 Then
WorkRng1.Find what:=r2.Value, LookIn:=xlValues
WorkRng2
是一个公共范围变量。
如何完成此代码以警告用户搜索失败?
答案 0 :(得分:1)
Find
找到范围 - 或不是。因此...
Dim Fnd As Range
Set Fnd = WorkRng1.Find(what:=r2.Value, LookIn:=xlValues)
If Fnd Is Nothing Then
' Nothing found
Else
' Fnd holds the cell that was found
End If