(Solved) – Delete row when cell is not equal a string in an array


I am trying to loop through an array and, when it finds a cell which is not equal a specific value, it deletes the entire row. Here is the code:

Sub DeleteTest()

Dim crr()

crr = Range("A3:A1000")

For i = LBound(crr, 1) To UBound(crr, 1)
    If (crr(i, 1) <> "One" And crr(i, 1) <> "Two") Then
       ' Line to delete the row in which the value of the cell is not One or Two

    End If

End Sub

I know I can also do it with an Autofilter, but I would like to know the way to do it with the array.

Leave a Reply

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