Why doesn't If Not IsEmpty filter out empty strings? Why doesn't If Not IsEmpty filter out empty strings? vba vba

Why doesn't If Not IsEmpty filter out empty strings?


In Visual Basic, Empty and "" (an empty string) are two different things. Empty is the uninitialized state of a Variant variable, and IsEmpty tests whether a Variant variable has the Empty value:

Dim x As VariantIf IsEmpty(x) Then    Debug.Print "x is empty"End If

As you've observed, you must compare against "" when checking whether a String variable contains an empty string.


If the variables are strings, you could also:

If Len(Wrkgps_L3) + Len(Wrkgps_L4) = 0 Then   ' They're both empty string variablesElse   ' One or the other contains at least one characterEnd If