View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default Starting a For Loop from the last Row and going upwards.

Thanks Jim. Works perfectly.

"Jim Thomlinson" wrote:

You can't with your existing code. Even if you could it will still cause
problems as the range you are traversing thorough is changing each time you
delete. On top of that deletes are slow and you are better off to accumulate
a single large range to delete. I would do it this way...

dim rngAll as range

For Each c In masterTrackerWs.Range("C2:C" & masterTrackerWs_lastRow).Cells
If c.Offset(0, 1).Text = "#N/A" And c.Offset(0, 2).Text = "#N/A" Then
if rngall is nothing then
set rngall = c
else
set rngall = union(rngall, c)
End If
Next c

if not rngall is nothing then rngall.entirerow.delete
--
HTH...

Jim Thomlinson


"Ayo" wrote:

If I wanted this for loop to start from the bottom row, how do I go about
doing that. I want the row deletion to start from the last row going upwards.

For Each c In masterTrackerWs.Range("C2:C" & masterTrackerWs_lastRow).Cells
If c.Offset(0, 1).Text = "#N/A" And c.Offset(0, 2).Text = "#N/A" Then
c.EntireRow.Delete
End If
Next c