I delete rows if a particular value is not found in a column.
Example Excel data:
Sl.No Content
1 Apple
2 Ball
3 Cat
4 Ball
5 Cat
Sub Delete()
Dim startrow As Long
'starting row number here
startrow = 2
' Assuming data to check is in A Column
Do Until startrow > Cells(Cells.Rows.Count, "A").End(xlUp).Row
If Cells(startrow, 2).Value = "Ball" Then
Rows(startrow).Delete
Else
startrow = startrow + 1
End If
Loop
End Sub
The output of this code:
Sl.No Content
1 Apple
3 Cat
5 Cat
This code is working.
Now I am trying to select the B column using the column header 'Content' and then delete the rows containing 'Ball' instead of providing the cell number.