I am trying to delete rows when a string is found (suffix of a string) but I think its failing because the row count changes after a row deletion?
Sub Test
'Remove rows where "Actual" string has -X-, -Y-, -Z- as suffix
With Sheets("Sheet4") 'Loop thru Column A
Sh4LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
Set Sh4Range = .Range("A2:A" & Sh4LastRow)
End With
For Each Sh4Cell In Sh4Range
If Right(Sh4Cell, 3) = "-X-" Or _
Right(Sh4Cell, 3) = "-Y-" Or _
Right(Sh4Cell, 3) = "-Z-" Then
'MsgBox Right(Sh4Cell, 3) 'for testing
Sh4Cell.EntireRow.Delete
End If
Next Sh4Cell
End Sub
I seem to have to run the macro a few times to get all the instances.
How do I reset the loop every time a row gets deleted?
Any hints, tips or examples are appreciated.
Bookmarks