空是行不通的 [英] Is empty is not working
问题描述
我正在编写程序,但无法正常工作. 我会写一个简单的版本
I m writing a program and it is not working. I will write a simple version of it
Dim rng as range
Dim message as integer
Set rng = Range(cells(1,1), cells (4,1))
If isempty(rng) then
mess = msgbox ("hello", vbyesno, "hello")
If mess = 6 then
Msgbox "hello"
Else
Msgbox "bye"
End if
Else
Msgbox "haha"
End if
这是程序, 但是,当单元格为空或单元格中有一个值时,它会执行else语句,即"haha",尽管它可能是正确的,但它不执行第一个语句. 为什么会发生,编写程序时我可能在做错什么.
This is the program, But when the cell is empty or if there is a value in the cell then it executes the else statement, that is "haha" and howsoever doesn't execute the first statement although it may be true. Why is it happening and what am i possibly doing wrong while writing the program.
推荐答案
IsEmpty
不是检测空单元格的Excel特定功能.
这是VB6/A语言的一部分,它检查类型Variant
的变量是否包含特殊值Empty
.
IsEmpty
is not an Excel-specific function that detects empty cells.
It's a part of the VB6/A language and it checks if the variable of type Variant
contains a special value, Empty
.
当检查单个 Excel单元格的内容时,它可以正常工作,因为可以理解表达式IsEmpty(cell)
IsEmpty(cell.Value)
,并且单个单元格的cell.Value
返回单个Variant
,该Variant
可能具有Empty
所检测到的特殊值Empty
.
It happens to work when checking contents of a single Excel cell because the expression IsEmpty(cell)
is understood as IsEmpty(cell.Value)
, and cell.Value
of a single cell returns a single Variant
that may have the special value of Empty
which IsEmpty
detects.
在其他情况下,它不起作用:
In other cases it does not work:
- 当您将多单元格范围传递给
IsEmpty
时,range.Value
返回一个Variant
s数组.数组本身永远不会是Empty
,即使其所有元素都包含Empty
. - 当传递
Nothing
的Range
变量时,IsEmpty
也无法检测到它,因为Empty
并非Nothing
.
- When you pass a multicell range to
IsEmpty
, therange.Value
returns an array ofVariant
s. An array itself is neverEmpty
, even when all its elements containEmpty
. - When you pass a
Range
variable that isNothing
,IsEmpty
cannot detect it either, becauseEmpty
is notNothing
.
这篇关于空是行不通的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!