-
Solved: Expression not running all the way through
I have this expression to delete the rows in which the cell in column D has the value "0" in it.
However this expression only deletes some of the rows where cell D is "0".
Do you see anything wrong with it?
[VBA]Sub tester2()
Dim lastrow As Long
Dim i As Long
With ActiveSheet
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 2 To lastrow
If .Cells(i, "D").Value = "0" Then
With Range(.Cells(i, "A"), .Cells(i, "X")).Select
Selection.Delete
End With
End If
Next i
End With
End Sub
[/VBA]
-
When deleting rows, one has to work from the bottom up
[VBA]For i = lastrow To 2 Step -1[/VBA]
-
[VBA]Sub tester2()
Dim lastrow As Long
Dim i As Long
With ActiveSheet
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = lastrow To 2 Step -1
If .Cells(i, "D").Value = "0" Then
With Range(.Cells(i, "A"), .Cells(i, "X")).Select
Selection.Delete Shift:=xlUp
End With
End If
Next i
End With
End Sub[/VBA]
that works great, thanks!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules