Search code examples
vbaexcelexcel-2007

VBA If Last Two Characters equals "XX" Then Delete Entire Row


I am trying to run a macro where it looks at a string and determines whether the last two characters equal "XX", then it is to delete the entire row.

I am getting a object error oh the highlighted below.

Sub Oval2_Click()


Last = Cells(Rows.Count, "E").End(xlUp).Row

For i = Last To 1 Step -1

`If (Right(Cells(i, "E"), 2).Value) = "TZ" Then`

    Cells(i, "E").EntireRow.Delete

End If
Next i

End Sub

Please help! Thank you.


Solution

  • Remove .Value from Right(Cells(i, "E"), 2).Value. It's complaining because .Value doesn't exist on the function Right