I am looping through rows of a table and deleting rows if certain conditions are not met. For some reason my for loop never exits even when its done. What am I doing wrong?<
if you want to loop and delete its best to mark the rows first and delete them at once or use an array.
lastr = Range("a2").End(xlDown).Row
dim DR() as long
dim c as long
For r = 2 To lastr
If Cells(r, 1).Value <> "SHORT POSITIONS" And Cells(r, 7).Value = 0 And Cells(r, 10).Value <> "Yes" Then
c = c +1
redim preserve DR(c)
dr(c-1) = R
End If
Next r
'delete the rows one by one, or you could build a string and delete once.
For r = 0 to UBound(DR)
Rows(dr(i).delete ' or entirerow delete
next i