gpt4 book ai didi

VBA做until循环条件?

转载 作者:行者123 更新时间:2023-12-03 00:55:26 24 4
gpt4 key购买 nike

我必须使用“DO UNTIL”条件,如果满足某些条件,我将给出一个

这里是例子。

对于工作表中的单元格(9,3),我必须检查单元格(9,3).value是否为

空或其“0”。如果是这样,我必须询问用户的输入,它应该

在1到100之间。我写了这样的代码

DO until 1<AA<100
if cells(9,3).value="" or cells(9,3).value="o" then
AA=InputBox("cells(9,3).value", "Enter only values as Numeric ", "give the value Here")
else
AA= cells(9,3).value
end if
loop

但它不会在 do 之后执行,直到它跳过所有步骤。请帮忙。

最佳答案

代码的问题是每次条件 (1 < AA < 100) 都会返回 true:

代码解释是这样的

C1 = (1 < AA)
C2 = C1 < 100

So, if:
AA > 1 Then C1 = 1 (True as VBA don't use strong types operators)
And if:
AA < 1 Then C1 = 0 (False as VBA don't use strong types operators)
Annnnd if:
AA is text, then C1 = 1 (Every non numeric character is bigger than an integer for VBA)
Then:
C1 = 1 or 0 or 1

The second condition will be:
C2 = C1 < 100
then
if C1 = 0 or if C1 = 1 both are less than 100, it causes that C2 will aways be true.

您需要做的就是使用三个条件,例如:

Do Until IsNumeric(AA) And 1 < AA And AA < 100

关于VBA做until循环条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34990286/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com