本文介绍了确定两个连续的单元格何时为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下While循环用于向下迭代一列,直到找到两个连续的空白单元格.只要curCell为空,它就会退出,而无需考虑lastCell中的值.在调试时,我已经验证了lastCell有一个值并且不为空,但是循环仍然存在.我的And语句出了点问题?

The following While loop is meant to iterate down a column until two consecutive blank cells are found. It exits as soon as curCell is empty, disregarding the value in lastCell. While debugging, I have verified that lastCell has a value and is not empty, but the loop still exits. Something wrong with my And statement?

While (lastCell <> "") And (curCell <> "")
    lastCell = curCell
    ActiveCell.Offset(1, 0).Select
    curCell = ActiveCell
Wend

推荐答案

您应使用Or代替And.

并要求这两个语句都为true,以使while循环继续进行.如果这些语句之一为假(如果一个单元格为空),则while循环将退出.

And requires both of those statements to be true in order for the while loop to continue. If one of those statements is false (if one cell is empty), the while loop will exit.

使用或",while语句将继续,直到两个单元格都为空白.

Using Or, the while statement will continue until both cells are blank.

这篇关于确定两个连续的单元格何时为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 21:03