-1

Here , var3 is empty but in the below condition not empty condition satisfies(which should not, because var3 is empty) and it goes inside the IF condition. I tried with Not IsEmpty method and also with var3 = "" in if condition. Can someone pls guide in this why its getting passed inside if condition.


If Not IsNull(var3) Or Not IsEmpty(var3) Then
MsgBox "Test"
oDoc.InsertDocument (insert_path2)
End If
braX
  • 11,506
  • 5
  • 20
  • 33
Tricky5
  • 37
  • 4
  • Your condition will always evaluate to true as 'not IsNull(empty)' is True. I suspect the test you want is really 'If Not IsNull(var3) and Not IsEmpty(var3) then' – freeflow Nov 18 '22 at 09:19
  • I also tried to get my head around this one. The top answer here explains it well: https://stackoverflow.com/questions/32489787/what-is-the-different-between-isnull-isempty-empty-and-an-empty-string-ie – user2924019 Nov 18 '22 at 09:23

1 Answers1

0

As this question is tagged with Excel, I believe it's related to cells, being empty or not. There there seems to be a difference between a cell, where nothing has ever been entered, and a cell, where something has been entered and deleted.

There is a simple way to overcome this difference: simply check the length of the content:

If Len(Range("A1")) = 0 Then
...
Dominique
  • 16,450
  • 15
  • 56
  • 112