I have a worksheet where some cells in column "B" contain strings (they all have "DELETE" in them in some form) while some cells are blank.
I want to delete all the rows where the cell in column "B" contains the string "DELETE" but keeping the rows where the cell in column "B" is blank.
I can only determine the range (lastrow) of the loop based on column "A" as it is filled down to the end.
Another thing I try to do in my loop is delete all rows where a cell in column "E" doesn't equal to the string "Active". This doesn't work.
The string "DELETE" could be upper or lower case randomly ("DELETE", "delete", "Delete" etc.)
My code deletes a few rows then stops.
Sub format_pull()
Dim sh1 As Worksheet
Set sh1 = Sheets("Sheet1")
LastRow = crc.Cells(Rows.Count, "A").End(xlUp).Row
For x = 2 To LastRow
If InStr(1, sh1.Range("B" & x).Value, UCase("DELETE"), 1) = 0 Then sh1.Range("B" & x).Value = "KEEP"
If sh1.Range("B" & x).Value = "DELETE" Then sh1.Range("B" & x).EntireRow.Delete
If sh1.Range("E" & x).Value <> "Active" Then sh1.Range("E" & x).EntireRow.Delete
Next x
End Sub
B, can there ever be a situation where the string in columnBhas a string but doesn't has the word DELETE in it? if so, what would you want to do then? - ZacIfcondition you haveUCase("DELETE"). As you already have the string DELETE in uppercase,UCaseis not needed here. Instead, havesh1.Range("B" & x).Valuein uppercase (i.e.UCase(sh1.Range("B" & x).Value)). I suspect that's part of the problem as your string in columnBmight not always be in uppercase - ZacInStrwithvbTextCompareso comparison is not case sensitive.. bottom line you don't needUCasewith this type of comparison. Change the other 2IF'sto useInStrin similar manner and implement Sam's suggestion. That should cure the issues - Zac