gpt4 book ai didi

excel - 出现错误的变量类型输入错误时重新运行 InputBox

转载 作者:行者123 更新时间:2023-12-04 21:11:57 26 4
gpt4 key购买 nike

我的目标是在 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/

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