exc*_*l34 58 excel vba excel-vba
如何在VBA语言中表达"如果值不为空"的条件?这是这样的吗?
"if value is not empty then..."
Edit/Delete Message
Run Code Online (Sandbox Code Playgroud)
Jon*_*ell 79
使用Not IsEmpty().
例如:
Sub DoStuffIfNotEmpty()
If Not IsEmpty(ActiveCell.Value) Then
MsgBox "I'm not empty!"
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
试试这个:
If Len(vValue & vbNullString) > 0 Then
' we have a non-Null and non-empty String value
doSomething()
Else
' We have a Null or empty string value
doSomethingElse()
End If
Run Code Online (Sandbox Code Playgroud)
小智 5
为什么不使用内置的Format()函数?
Dim vTest As Variant
vTest = Empty ' or vTest = null or vTest = ""
If Format(vTest) = vbNullString Then
doSomethingWhenEmpty()
Else
doSomethingElse()
End If
Run Code Online (Sandbox Code Playgroud)
Format()将捕获空变量以及null变量并将其转换为字符串.我将它用于null/empty验证之类的东西,并检查是否在组合框中选择了一个项目.