我必须使用'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
但它没有做到直到它跳过所有步骤。请帮忙。
答案 0 :(得分:5)
代码的问题在于每次条件(1
代码解释将是这样的
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