View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett Don Guillett is offline
external usenet poster
 
Posts: 10,124
Default For Each loop recheck

Work from the bottom up. Use this idea and report you final solution here.

for i = 500 to 7 step -1
if cells(i,"a")="mycriteria" then rows(i).delete
next i

--
Don Guillett
SalesAid Software

"Riddler" wrote in message
ups.com...
I have a for each loop that loops through a range of cells. My problem
is that if my criteria is met I delete the current row. The problem is
that the for each loop moves on to the next item which is really 1 more
down now that I deleted a row. How can I make it recheck the current
row? I basically want it to back up 1 and then let the for each move
ahead 1 to get me to the same line (which is the new one because of the
deleted row).

Here is the code I have.

Sub MoveCompleted()
Dim LastRow
For Each cell In Sheets("Master Project List").Range("I7:I500")
Debug.Print cell.Value
If cell < "" Then
Row = cell.Row
Sheets("Completed Projects").UsedRange '<<-- Reset Used
Range!!
LastRow = Sheets("Completed
Projects").Cells.SpecialCells(xlCellTypeLastCell). Row + 1
Sheets("Master Project List").Range(Row & ":" & Row).Cut
Sheets("Completed Projects").Range(LastRow & ":" & LastRow)
Sheets("Master Project List").Range(Row & ":" & Row).Delete
End If
Next cell
End Sub

Thanks
Scott