Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are Len(cell.Value) = 0 and cell.Value = "" equivalent in Excel?

Tags:

excel

vba

When evaluating the value of a cell in a worksheet in Excel, is the following statement true?

If and only if Len(cell.Value) = 0, then cell.Value = "".

This would imply that it is safe to check that there are zero characters in a cell instead of comparing the cell value to an empty string.

like image 841
strcompnice Avatar asked Feb 02 '11 10:02

strcompnice


2 Answers

Yes, they do the same thing.

However, I would advise that you use the IsEmpty function to check for empty cells. If you enter a single quote into a cell ' both the len check and the ="" check will both state the the cell is empty. When in actual fact it isn't.

IsEmpty will return false in this scenario.

And it's also a little easier to read.

like image 154
codingbadger Avatar answered Sep 28 '22 02:09

codingbadger


I'm quite sure your statement is true. I've been using it for quite a while and never had an issue with that assumption

My two cents : I'm not sure you gain a lot of performance from the trick, and it maybe easier for other people to understand the meaning of cell.Value = "" than Len(cell.Value) = 0

like image 21
Sébastien Nussbaumer Avatar answered Sep 28 '22 01:09

Sébastien Nussbaumer