Application.Wait和Excel VBA运行时错误'13'类型不匹配

od

我不明白为什么会有该行Application.Wait in error(以黄色突出显示)?

Sub Wait_Random()
Dim Low As Double
Dim High As Double
Low = 90 '<<< CHANGE AS DESIRED
High = 126 '<<< CHANGE AS DESIRED
r = Int((High - Low + 1) * Rnd() + Low)
Application.Wait Now + TimeValue("00:00:" & CStr(r))
End Sub

我发现问题在于此代码正在尝试“将数字添加到字符串中”。但是我迷路了!提前致谢 ;)

德米特里·帕夫利夫(Dmitry Pavliv)

这是因为您的r变量始终大于59秒。(实际上是alwasys大于90)。您应该进行更改LowHigh这样r永远不会比以往更大59:

Sub Wait_Random()
    Dim Low As Double
    Dim High As Double
    Dim r as Integer
    Low = 1 '<<< CHANGE AS DESIRED
    High = 59 '<<< CHANGE AS DESIRED
    r = Int((High - Low) * Rnd() + Low)
    Application.Wait Now + TimeValue("00:00:" & CStr(r))
End Sub

或您可以使用的另一种方式

Application.Wait DateAdd("s", r, Now)

增加r秒数。在那种情况下r可能更大59

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Excel VBA运行时错误类型不匹配13

Excel VBA运行时错误“ 13”:类型不匹配

运行时错误 13' 类型不匹配 VBA excel

Excel VBA运行时错误“ 13”:将变量数组传递给Application.Index方法时,类型不匹配

VBA Excel中的“运行时错误13:类型不匹配”错误

Excel运行时错误13中的VBA:类型不匹配

Excel VBA数据透视缓存类型不匹配运行时错误'13'

尝试检测是否关闭了用户窗体时在Excel VBA中得到“运行时错误'13':类型不匹配”

运行时错误'13:比较日期时键入不匹配-EXCEL VBA

VB Excel 2010运行时错误'13':类型不匹配

VBA Excel“错误13:类型不匹配”

运行时错误13 VBA Excel

Access 2010 VBA类型不匹配(错误13)或运行时错误424(必需的对象)

Excel Application.Match运行时错误'13'

运行时错误“13”:宏中的类型不匹配

运行时错误'13':类型不匹配,定义了PivotCahe

运行时错误13,类型不匹配MsgBox取消

运行时错误“13”类型不匹配:如果或

类型不匹配运行时错误13

运行时错误13 /类型不匹配

工作表运行时错误“13”:类型不匹配

我在VBA excel中编写编码器。我不断收到运行时错误13。它说不匹配

更新汇率-VBA-运行时错误13类型不匹配

VBA Scripting.dictionary运行时错误'13'类型不匹配

运行时错误13输入不匹配〜当Application.Inputbox取消时

VBA 过滤器函数在从范围创建的数组上引发“运行时错误 13:类型不匹配”错误

运行-时间错误“ 13”:类型不匹配-Excel用户窗体

运行时错误13 VBA Excel 2007

Excel VBA If语句多条件运行时错误13