Click here to Skip to main content
15,891,749 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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
Posted
Updated 21-Sep-16 6:12am
Comments
[no name] 21-Sep-16 12:08pm    
Why can't you check if b is greater than zero? Am I missing something here?

1 solution

Simple: don't divide by zero.

Which means: check your inputs.
VB
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900