空是行不通的 [英] Is empty is not working

查看:73
本文介绍了空是行不通的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写程序,但无法正常工作. 我会写一个简单的版本

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.
  • 当传递NothingRange变量时,IsEmpty也无法检测到它,因为Empty并非Nothing.
  • When you pass a multicell range to IsEmpty, the range.Value returns an array of Variants. An array itself is never Empty, even when all its elements contain Empty.
  • When you pass a Range variable that is Nothing, IsEmpty cannot detect it either, because Empty is not Nothing.

这篇关于空是行不通的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆