我有这个
Set rngFound = Selection.Find(What:=Trim(prirustek.Cells(i, 1).Value), LookIn:=xlValues, LookAt:=xlWhole)
并且需要做这样的事情:
If rngFound Is Nothing Or rngFound = "" Then
...
但此代码以“对象变量或未设置块变量(错误91)”停止。我认为这个问题在rngFound中没什么,但我怎么能
rngFound = ""
在IF声明中?
答案 0 :(得分:2)
试试这个If IIf(rng Is Nothing, "", rng) = "" Then
首先处理整个nothing
情况。这有点像Access中的Nz()
。
答案 1 :(得分:0)
尝试If rngFound Is Nothing Or rngFound.Value = "" Then
答案 2 :(得分:0)
怎么样:
Private Function isRangeEmptyOrNothing(r As Range) As Boolean
If r Is Nothing Then
isRangeEmptyOrNothing = True
ElseIf IsEmpty(r) Then
isRangeEmptyOrNothing = True
ElseIf r = "" Then 'Not sure if this is redundant with IsEmpty
isRangeEmptyOrNothing = True
End If
End Function
然后在你的主要代码中:
If isRangeEmptyOrNothing(rngFound) Then
答案 3 :(得分:0)
您可以尝试以下操作:
If rngFound = Empty Then ...
或
If isNull(rngFound) = true Then ...