tags:

views:

99

answers:

4

Hi,

how do I express the condition "if value is not empty " in VBA language ? Is it something like this ?

"if value is not empty then.." Edit/Delete Message

A: 

Try this:

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

taken from here

alexphi
A: 

I am not sure if this is what you are looking for

if var<>"" then
           dosomething

or

if isempty(thisworkbook.sheets("sheet1").range("a1").value)= false then

the ISEMPTY function can be used as well

Anthony
A: 

It depends on what you want to test:

  • for a string, you can use IF strName = vbNullString or IF strName = ""
  • for an object, you can use iF myObject is nothing
  • for a recordset field, you could use if isnull(myField)
  • for an Excel cell, you could use if range("B3") = ""

Etc... Maybe your question should be more specific ?

iDevlop
A: 

Why not just use the built-in Format() function?

Dim vTest As Variant
vTest = Empty ' or vTest = null or vTest = ""

If Format(vTest) = vbNullString Then
    doSomethingWhenEmpty() 
Else
   doSomethingElse() 
End If

Format() will catch empty variants as well as null ones and transforms them in strings. I use it for things like null/empty validations and to check if an item has been selected in a combobox.

Marcand