View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
George Nicholson George Nicholson is offline
external usenet poster
 
Posts: 149
Default Why is this loop not working?

Reverse the loop.

For iloop = irows to 2 Step -1

When deleting rows (or any object in a Collection) by index position, start
with the LAST member, and work forward.
The reason is that once you delete, the "next" highest element fills the
current index position...but you just evaluated the current position and are
about to move off of it. Result: every time you delete you end up 'skipping'
the next highest row/object and it is never evaluated. This isn't an issue
if you work backwards from the end of the collection.

When its possible to use a For Each..Next structure, this isn't an issue.
Each member will be evaluated.

HTH,


"Mike R." wrote in message
...
Hi -
this seems like a pretty easy loop statement. What am I doing wrong? I
am
trying to see if a value in a row equal's the word START and if so, delete
that row.
Help..

irows = ActiveSheet.UsedRange.Rows.Count
For iloop = 2 To irows
If Cells(iloop, "D").Value = "START" Then Cells(iloop,
"D").EntireRow.Delete
Next iloop