Excel VBA deleting rows in a for loop misses rows

Work from the bottom up. If you delete a row, everything moves up and you skip that row on the next iteration.

Here is the ‘guts’ of the code to work up from the bottom.

With Worksheets("Sheet1")
    For rw = .Cells(.Rows.Count, "B").End(xlUp).Row To 2 Step -1
        Select Case UCase(.Cells(rw, "B").Value2)
            Case "FG", "QC", "CS"
                .Rows(rw).EntireRow.Delete
        End Select
    Next rw
End With

Leave a Comment