PDA

View Full Version : Solved: Step Backwards through range



plawrenz
05-04-2012, 01:02 PM
I am trying to step backwards through a range since I am trying to delete rows. Here is my code. i just need it to start at A150 and go through A7. In fact it would be better if the end of the range could be dynamic. Thanks for the help:
With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) Then


Set r1 = Range("A7:A150")
For Each c1 In r1
If c1.Value = .List(i) Then
c1.Font.Bold = True
With c1
c1.EntireRow.Delete
End With
End If
Next c1

End If
Next i
End With

xld
05-04-2012, 04:35 PM
With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) Then

lastrow = cell(Rows.Count, "A").End(xlUp).Row

For ii = lastrow To 7 Step -1
If Cells(ii, "A").Value = .List(i) Then
Cells(ii, "A").Font.Bold = True
Rows(ii).Delete
End If
Next i
End If
Next i
End With

Aussiebear
05-04-2012, 08:04 PM
Be careful with XLD's code because it uses Lastrow. Lastrow might be beyond the A150 limit you indicated in the initial post.