View Single Post
  #5   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

Why not learn to do it properly?

--
Don Guillett
SalesAid Software

"Riddler" wrote in message
ups.com...
Here is what I came up with. It is crude but works good. When it
deletes a row it jumps out of the loop and starts over again. My list
will never be very long so it wont have any performance issues.

Private Sub CommandButton1_Click()
Dim LastRow
10 For Each cell In Sheets("Master Project List").Range("I7:I500")
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("A" & Row & ":" & "P" &
Row).Cut Sheets("Completed Projects").Range(LastRow & ":" & LastRow)
Sheets("Master Project List").Range("A" & Row & ":" & "P" &
Row).Delete
GoTo 10 'Restart the loop because a row was deleted
End If
Next cell
With Sheets("Completed Projects").Range("A4:P40000")
.Sort Key1:=Sheets("Completed Projects").Range("I3"),
Order1:=xlDescending
End With
End Sub


Scott