(Solved) – Reverse Loop ignores some cells

(solved)-–-reverse-loop-ignores-some-cells

I have written a small code that allow me to:
in a defined range (xrng) in column F, find all the cells that contain certain text and once found, select all the cells in the range A:G on the same row and delete them. I have a reverse loop, which work partially, as ignores some cells in the range, specifically the 2nd and the 3rd. Below a before and after pic:

enter image description here

Here my code:

  Sub removeapp()

    Dim g As Long, xrng As Range, lastrow As Long, i As Long
    i = 4
    lastrow = Cells(Rows.Count, "F").End(xlUp).Row
    Set xrng = Range(Cells(lastrow, "F"), Cells(i, "F"))

        For g = xrng.Count To i Step -1

            If xrng.Cells(g).Value = "Adjustment" Or xrng.Cells(g).Value = "Approved" Then
            Range(Cells(xrng.Cells(g).Row(), "A"), Cells(xrng.Cells(g).Row(), "G")).Delete
            End If

        Next

    End Sub

Could you help me to figure out why?
Also, the code runs really slow… if you have any tip to make it slighlty faster would be great!

Leave a Reply

Your email address will not be published. Required fields are marked *