我的目标是在 InputBox 崩溃时重新运行它,并给用户另一个机会来提供正确的输入类型。 (就像它崩溃一样,你会得到一个消息框,上面写着“抱歉你的条目不可用,请重试”,然后它会跳回输入框。)
Test1:
qm = InputBox("Wie viele Quadrat Meter hat die Wohnung?" & vbLf & "Bitte geben sie die QM Zahl an.", Angabe)
If IsError(qm) Then GoTo Test1
qm
定义为 Integer
, =0,下面有一个Select Case
改变 qm
的多种选择到 1-600 之间的数字。当我输入像“嘿,伙计们”这样的文本时,Excel 给了我错误 13(运行时错误 13':类型不匹配)。
最佳答案
这就是为什么在 VBA 中你可以使用 Application.InputBox
第 4 个参数 Type
.如果您使用 Type:=1
那么只允许使用数值。
代码 :
Dim qm As Integer
qm = Application.InputBox("Wie viele Quadrat Meter hat die Wohnung?" _
& vbLf & "Bitte geben sie die QM Zahl an.", "Angabe", Type:=1)
关于excel - 出现错误的变量类型输入错误时重新运行 InputBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46192057/