I want to delete rows from Excel if Column A contains "string1" as shown in the following table:
| A1 | B1 | 
|---|---|
| string1 string2 | string3 string4 | 
| string5 string6 | string7 string8 | 
I'm using the below code:
 Sub DeleteRows()
    Dim rng As Range
    Dim pos As Integer
    Set rng = ActiveSheet.UsedRange
    
    For i = rng.Cells.Count To 1 Step -1
        pos = InStr(LCase(rng.Item(i).Value), LCase("string1"))
        If pos > 0 Then
            rng.Item(i).EntireRow.Delete
        End If
    Next i
End Sub
The problem is that if the Column A contains "string11" not "string1" it's also deleting the row. Any advice, please? Thanks
 
     
     
     
    