Kā izteikt nosacījumu "if value is not empty" VBA valodā? Vai tas ir kaut kas līdzīgs šim?
"if value is not empty then..."
Edit/Delete Message
Izmēģiniet šo:
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
Neesmu pārliecināts, vai tas ir tas, ko jūs meklējat.
if var<>"" then
dosomething
vai
if isempty(thisworkbook.sheets("sheet1").range("a1").value)= false then
var izmantot arī funkciju ISEMPTY
Alexphi's ieteikums ir labs. To var arī kodēt, vispirms izveidojot mainīgo kā Variant
un pēc tam piešķirot to Empty
. Pēc tam veiciet if/then ar, lai to, iespējams, aizpildītu. Ja tas piepildās, tas nav tukšs, ja nepiepildās, tas paliek tukšs. Tad to pārbauda ar IsEmpty
.
Sub TestforEmpty()
Dim dt As Variant
dt = Empty
Dim today As Date
today = Date
If today = Date Then
dt = today
End If
If IsEmpty(dt) Then
MsgBox "It not is today"
Else
MsgBox "It is today"
End If
End Sub