When evaluating the value of a cell in a worksheet in Excel, is the following statement true?
在Excel中评估工作表中单元格的值时,以下语句是否为真?
If and only if Len(cell.Value) = 0
, then cell.Value = "".
当且仅当Len(cell.Value)= 0时,则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.
这意味着可以安全地检查单元格中是否有零个字符,而不是将单元格值与空字符串进行比较。
2 个解决方案
#1
7
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函数检查空单元格。如果在单元格中输入单引号,则len检查和=“”检查都将表明单元格为空。实际上事实并非如此。
IsEmpty
will return false in this scenario.
在这种情况下,IsEmpty将返回false。
And it's also a little easier to read.
而且它也更容易阅读。
#2
1
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
我的两分钱:我不确定你从这个技巧中获得了很多表现,并且其他人可能更容易理解cell.Value =“”而不是Len(cell.Value)= 0
#1
7
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函数检查空单元格。如果在单元格中输入单引号,则len检查和=“”检查都将表明单元格为空。实际上事实并非如此。
IsEmpty
will return false in this scenario.
在这种情况下,IsEmpty将返回false。
And it's also a little easier to read.
而且它也更容易阅读。
#2
1
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
我的两分钱:我不确定你从这个技巧中获得了很多表现,并且其他人可能更容易理解cell.Value =“”而不是Len(cell.Value)= 0