Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 VBA 中有一个通常返回数组的函数。如果没有要返回的内容,则返回一个空变量 ( b = empty)。我有一些代码可以循环遍历数组,但如果变量不是数组,则会出现错误。如何做出不会导致自身错误的 if 语句。我努力了
b = empty
if not b = empty then 'do the loop end if
但是当 b 是一个数组b = null时b = nothing会出错b(1,1) = ""
b = null
b = nothing
b(1,1) = ""
检查这个的最好方法是什么?
要测试变量是否为空,请使用IsEmpty函数。
If IsEmpty(b) Then Debug.Print "b is Empty" End If
要测试变量是否为数组,请使用VarType函数。
If VarType(b) And vbArray Then Debug.Print "b is an array" End If