Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何解决vba中的运行时错误6?_Vba_Excel - Fatal编程技术网

如何解决vba中的运行时错误6?

如何解决vba中的运行时错误6?,vba,excel,Vba,Excel,我有以下代码 TextBox50.Value = Round((CDbl(TextBox3.Value) / (CDbl(Worksheets("calculation").Range("O4").Value)) - 1) * 100, 1) & "%" TextBox3的值=工作表Calculation.RangeO4中的值 问题是如果RangeO4的值为零,那么它实际上意味着0/0,这就是为什么我得到运行时6,溢出错误 我是否可以用0替换0/0 非常感谢您的帮助。谢谢你对于你有被零

我有以下代码

TextBox50.Value = Round((CDbl(TextBox3.Value) / (CDbl(Worksheets("calculation").Range("O4").Value)) - 1) * 100, 1) & "%"
TextBox3的值=工作表Calculation.RangeO4中的值

问题是如果RangeO4的值为零,那么它实际上意味着0/0,这就是为什么我得到运行时6,溢出错误

我是否可以用0替换0/0


非常感谢您的帮助。谢谢你

对于你有被零除问题的情况,类似的方法应该有效:

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

类似的方法应该适用于存在被零除问题的情况:

If CDbl(Worksheets("calculation").Range("O4").Value) = 0 Then
   TextBox50.Value = (0 - 1) * 100, 1) & "%"
Else
    TextBox50.Value = Round((CDbl(TextBox3.Value) / (CDbl(Worksheets("calculation").Range("O4").Value)) - 1) * 100, 1) & "%"
End If
您可以使用IIF:

TextBox50.Value = Round((CDbl(TextBox3.Value) / IIF(CDbl(Worksheets("calculation").Range("O4")=0,1,CDbl(Worksheets("calculation").Range("O4")))
如果另一个为0,则返回TextBox3中的值。

您可以使用IIF:

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

如果另一个为0,它将返回TextBox3中的值。

是否存在可以将输出显示为NA或-或NULL的位置是否存在可以将输出显示为NA或-或NULL的位置