在下面的代码中“Not Rng Is Nothing”(在if中)的含义是什么?

时间:2016-09-04 12:11:08

标签: vba nothing

假设您有一个产品列表(列A),旁边有总计。如果您要查找任何总数(列B)等于零并将LOW放在其旁边的单元格中(列C),请执行以下操作:

Set Rng = Range("B1:B16").Find(What:="0", LookAt:=xlWhole, LookIn:=xlValues)
Rng.Offset(, 1).Value = "LOW"

Sub MyOffset()
    With Range("B1:B16")
        Set Rng = .Find(What:="0", LookAt:=xlWhole, LookIn:=xlValues)
        If Not Rng Is Nothing Then
            firstAddress = Rng.Address
            Do
                Rng.Offset(, 1).Value = "LOW"
                Set Rng = .FindNext(Rng)
                Loop While Not Rng Is Nothing And Rng.Address <> firstAddress
        End If
    End With
End Sub

1 个答案:

答案 0 :(得分:1)

Find()方法在匹配其参数中指定的条件(“What”,“LookIn”,“LookAt”,...)时调用范围内的单元格,并返回找到的单元格引用(如果找不到匹配项,则为Range对象)或空引用对象(使用关键字Nothing引用)