【问题标题】:Loop if condition and search. What to do something if value isn't found循环 if 条件和搜索。如果没有找到价值怎么办
【发布时间】:2018-07-25 16:45:10
【问题描述】:

如果值符合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 是一个公共范围变量。

如何完成此代码以警告用户搜索失败?

【问题讨论】:

    标签: excel loops find vba


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-16
      • 1970-01-01
      • 1970-01-01
      • 2017-04-02
      • 1970-01-01
      • 1970-01-01
      • 2019-04-22
      • 2019-12-24
      相关资源
      最近更新 更多