vba 单元格为空,但 IsEmpty 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19105452/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cell is empty but IsEmpty is not working
提问by Cecilia Moneta
I am writing an IF statement that uses the IsEmpty function to determine if True or False. I tried it both on a cell with a value (e.g., PRB2039) and on a blank cell to test my code, and the result is the same.
我正在编写一个 IF 语句,它使用 IsEmpty 函数来确定是 True 还是 False。我在具有值的单元格(例如 PRB2039)和空白单元格上尝试了它来测试我的代码,结果是相同的。
I removed formatting, and tried it on a new worksheet. I don't know what I'm doing wrong.
我删除了格式,并在新工作表上进行了尝试。我不知道我做错了什么。
回答by Siddharth Rout
I prefer using
我更喜欢使用
If Len(Trim(Cells(i, 1).Value))=0 Then Msgbox "Empty"
回答by Santosh
As suggested by @PatricK you may consider using ISBLANK function instead of IsEmpty function. ISBLANKfunction Returns TRUE if the value is blank
正如@PatricK 所建议的,您可以考虑使用 ISBLANK 函数而不是 IsEmpty 函数。ISBLANK函数如果值为空则返回 TRUE
Using VBA
使用 VBA
Sub test()
For i = 1 To 4
MsgBox Evaluate("isblank(" & Cells(i, 1).Address & ")")
Next
End Sub