I have some 100 rows with some 10 columns.I want to delete the entire row if the cell in column B(or 2) contains a specific string "XYZ" (say)
The below code works perfect if the string is present in the beginning. But I want it to work for below cases as well:
- "XYZadjsaoda" (Case 1: Beginning of the string)
- "asdsalXYZasdsa" (Case 2: Middle of the string )
- "dsadsad32XYZ" (Case 3: End of the string)
If the string is present it should delete the entire row.
Sub DeleteRowBasedOnCriteria()
Dim RowToTest As Long
Sheets("Jira").Select
For RowToTest = Cells(Rows.Count, 2).End(xlUp).Row To 2 Step -1
With Cells(RowToTest, 2)
If .Value = "XYZ" _
Then _
Rows(RowToTest).EntireRow.Delete
End With
Next RowToTest
End Sub
The function should match XYZ irrespective of the location inside a cell and delete entire row.