Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Avoid deleting by zero

Status
Not open for further replies.

Navvy

Technical User
Apr 12, 2002
64
US
Hello, I have the following piece of code which checks that if Column 7 is NOT within 1% of column 11 or column 12 then delete. The problem is the value in 11 or 12 could be a zero and we can't divide by zero. How can I do something that says if Col. 11 is zero skip that and look at 12 or if col 12 is zero skip that and look in col 11?

Sub deleteif()
Endrow = Range("G65536").End(xlUp).Row

For i = Endrow To 2 Step -1
If Abs(Cells(i, 7).Value - Cells(i, 11).Value) / Cells(i, 11).Value > 0.01 Then
If Abs(Cells(i, 7).Value - Cells(i, 12).Value) / Cells(i, 12).Value > 0.01 Then
Cells(i, 7).EntireRow.Delete
End If
End If
Next i

End Sub

 
Use the following logic:

if A=0 and B=0 then
dodelete=true
elseif A=0 then
dodelete=(B is small)
elseif B=0 then
dodelete=(A is small)
else dodelete=(A is small) and (B is small)

if dodelete then ...

where you fill in your expressions for A, B, and "is small"
Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top