如何解决vba中的运行时错误6? [英] How to Solve runtime error 6 in vba?

查看:647
本文介绍了如何解决vba中的运行时错误6?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码

TextBox50.Value = Round((CDbl(TextBox3.Value) / (CDbl(Worksheets("calculation").Range("O4").Value)) - 1) * 100, 1) & "%"

TextBox3 = Value 存在于工作表(计算)。范围(O4)

问题是如果Range(O4)的值为零,那么它本质上意味着0/0,这就是为什么我得到运行时6,溢出错误。

The issue is if the value of Range(O4) is zero, then it essentially means 0/0 which is why I am getting runtime 6, overflow error.

有没有办法可以用0替换0/0。

Is there anyway I can replace 0/0 with 0.

任何帮助都非常感谢。谢谢

Any help is much appreciated. Thank you

推荐答案

您可以使用IIF():

You can use IIF():

TextBox50.Value = Round((CDbl(TextBox3.Value) / IIF(CDbl(Worksheets("calculation").Range("O4")=0,1,CDbl(Worksheets("calculation").Range("O4")))

如果另一个则返回TextBox3中的值是0。

Which will return the value in TextBox3 if the other is 0.

这篇关于如何解决vba中的运行时错误6?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆