如何在此处避免除零问题 [英] How do I avoid division by zero issue here
问题描述
我有大约500个数据和大约100个数据代码停止,因为除零错误
我尝试过:
Application.Range(o7)。激活
'数据的计数存储在变量
Application.Range(Selection,Selection.End(xlDown))。选择
a = Application.CountA(选择)
范围(o7)。激活
'循环函数用于数据计数
For i = 1 to a
ActiveCell.Offset(0,1) .Activate
b = ActiveCell.Value
ActiveCell.Offset(0,1)。激活
c = ActiveCell.Value
ActiveCell.Offset(0,1).Activate
e =(c / b)* 100
'数据的值存储在一个变量中并用于计算SAMPLE COMPLIANCE使用另一个变量
ActiveCell.Value = e
ActiveCell.Offset(1,-3)。激活
下一页
Application.ScreenUpdating = Fals e $>
End Sub
简单:不要除以零。
这意味着:检查你的输入。
b = ActiveCell.Value
ActiveCell.Offset( 0 , 1 )。激活
c = ActiveCell.Value
ActiveCell.Offset( 0 , 1 )。激活
e = -1
如果 b <> 0 然后
e =(c / b)* 100
结束 如果
i have around 500 data and at around 100th data the code is stopping because of the error of division by zero
What I have tried:
Application.Range("o7").Activate
'count of the data is stored inn the variable
Application.Range(Selection, Selection.End(xlDown)).Select
a = Application.CountA(Selection)
Range("o7").Activate
'loop function is used till the count of the data
For i = 1 To a
ActiveCell.Offset(0, 1).Activate
b = ActiveCell.Value
ActiveCell.Offset(0, 1).Activate
c = ActiveCell.Value
ActiveCell.Offset(0, 1).Activate
e = (c / b) * 100
'values of the data are stored in a variable and for calculating the SAMPLE COMPLIANCE another variable is used
ActiveCell.Value = e
ActiveCell.Offset(1, -3).Activate
Next
Application.ScreenUpdating = False
End Sub
Simple: don't divide by zero.
Which means: check your inputs.
b = ActiveCell.Value ActiveCell.Offset(0, 1).Activate c = ActiveCell.Value ActiveCell.Offset(0, 1).Activate e = -1 If b <> 0 Then e = (c / b) * 100 End If
这篇关于如何在此处避免除零问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!