【问题标题】:VBA User Form does not recognize if function?VBA用户表单无法识别功能?
【发布时间】:2016-08-25 07:57:44
【问题描述】:
Private Sub ROLparameter_Click()
Line1: RolLow = InputBox("Please enter the lower bound percentage for ROL calculation between 0 and 100 (initially " & RolLow * 100 & "%):")

If Not 0 <= RolLow <= 100 Then GoTo Line1
End If

End Sub

我有用户表单按钮,当我按下它会进入这个子。问题是它给出了错误“如果没有如果则结束”。当我删除 end if 时,它的工作原理很奇怪。

如;

当用户输入 80 时,它确实将 RolLow 值识别为“80”。如果不将它定向到 end sub,如果我只使用“if”,那么它将一直定向到第 1 行。不检查值。

此代码在模块中正常工作。

可能是什么问题?

(变量在 subs 之前定义为 public)

(我也试过 module.variable 的东西)

【问题讨论】:

  • 试试我下面回答中的代码

标签: excel userform vba


【解决方案1】:

这是您尝试运行的代码: 如果用户输入的值小于 0 或大于 100,则返回 InputBox

Private Sub ROLparameter_Click()

Line1: Rollow = CLng(InputBox("Please enter the lower bound percentage for ROL calculation between 0 and 100 (initially " & Rollow * 100 & "%):"))

If Not ((0 <= Rollow) And (Rollow <= 100)) Then
    GoTo Line1
End If

End Sub

【讨论】:

  • CLng 将输入(作为字符串接收)转换为 Long,如果您想要更小的值,也可以使用CInt
  • 再次感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-01-06
  • 1970-01-01
  • 1970-01-01
  • 2012-07-17
  • 2021-01-22
  • 2019-08-01
  • 2011-10-01
相关资源
最近更新 更多