开发者

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

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开发者_如何学C, 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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜