View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default Starting a For Loop from the last Row and going upwards.

Hi,

This is how to do it backwards

For x = masterTrackerWs_lastRow To 2 Step -1
If Cells(x, 4).Text = "#N/A" And Cells(x, 5).Text = "#N/A" Then
Rows(x).EntireRow.Delete
End If
Next

but you don't have to, using your method. Build up a new range of relevent
cells and delete all in one go

Sub subtest1()
Dim copyrange As Range
Set masterTrackerWs = ActiveSheet
masterTrackerWs_lastRow = Cells(Cells.Rows.Count, "C").End(xlUp).Row
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 copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If
End If
Next c
If Not copyrange Is Nothing Then
copyrange.Delete
End If




End Sub

Mike


"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