# vba Delete Rows with found text



## Peterfc2 (Jan 7, 2023)

Found this by Rick Rothstein from January 25, 2012. (Yes I have seen the date)

If your entries in Column 2 are text constants (that is, there are no formulas in the column), then this non-looping macro should do what you want quite quickly...
I need to alter it so it deletes the row below too. Anyone know how?


```
Sub DeleteRowsInColumn2WithTempInThem()
  On Error Resume Next
  With Columns("B")
    .Replace "*temp*", "=1", xlWhole
    .SpecialCells(xlFormulas).EntireRow.Delete
  End With
End Sub
```


----------



## shinigamilight (Jan 7, 2023)

You will have to write a looping macro for that.


----------



## Peterfc2 (Sunday at 2:45 AM)

If LastRow is an odd number it does the odd rows.

```
Sub Button1_Click()


Dim i As Long
Dim LastRow As Long

With ActiveSheet
LastRow = 99
For i = LastRow To 1 Step -2
.Rows(i).Delete
Next i
End With

Range("A1").Select
End Sub
```


----------



## Alex Blakenburg (Sunday at 7:13 AM)

What are you actually trying to do ? ie what are your criteria for selecting the rows you want to delete ?


----------

