如果返回TRUE,则IF返回FALSE [英] IF returns FALSE when it sould return TRUE
本文介绍了如果返回TRUE,则IF返回FALSE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图做这样的事情
sub test()
a=inputbox("value1:")
b=inputbox("value2:")
c=inputbox("value3:")
if a<b and a>c then
msgbox(a)
else
msgbox(b)
msgbox(c)
end if
end sub
当我为a输入5,为b输入10,为c输入2时,条件应返回TRUE,然后消息框带有显示了a,但返回FALSE并显示带有b和c的消息框。我认为解决方案非常简单,但我无法解决。
when I enter values such as 5 for a, 10 for b and 2 for c, condition should return TRUE and then message box with a is shown, but it returns FALSE and displays message boxes with b and c. I think the solution is pretty simple but I can't figure it out.
非常感谢
推荐答案
这是因为VBA正在处理您的输入为字符串。只需在变量中添加CInt()或CLng()即可知道它们是数字。
This happens because VBA is treating your input as strings. Just add a CInt() or a CLng() to the variables to excel know that they are numeric.
Sub test()
a = CInt(InputBox("value1:"))
b = CInt(InputBox("value2:"))
c = CInt(InputBox("value3:"))
If a < b And a > c Then
MsgBox (a)
Else
MsgBox (b)
MsgBox (c)
End If
End Sub
这篇关于如果返回TRUE,则IF返回FALSE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文