Forum Discussion
LonnieCurrier
May 18, 2020Copper Contributor
Deleting rows in a macro based on cell contents
I am wondering if there is a faster way to delete selected rows in a macro. I recorded this short macro using data filter to select all rows with nothing in the first column, then deletes them all. ...
- May 19, 2020
LonnieCurrier Taking your request literally, try this:
Dim lastRow As Object Dim i As Integer Set lastRow = Range("A1").CurrentRegion For i = lastRow.Rows.Count To 2 Step -1 If lastRow.Cells(i, 1) = "BAD" _ Or lastRow.Cells(i, 1) = "UGLY" _ Or lastRow.Cells(i, 1) = "AWFUL" Then Cells(i, 1).EntireRow.Delete End If Next
Riny_van_Eekelen
May 19, 2020Platinum Contributor
LonnieCurrier Taking your request literally, try this:
Dim lastRow As Object
Dim i As Integer
Set lastRow = Range("A1").CurrentRegion
For i = lastRow.Rows.Count To 2 Step -1
If lastRow.Cells(i, 1) = "BAD" _
Or lastRow.Cells(i, 1) = "UGLY" _
Or lastRow.Cells(i, 1) = "AWFUL" Then
Cells(i, 1).EntireRow.Delete
End If
Next
LonnieCurrier
May 19, 2020Copper Contributor
Riny_van_EekelenThanks again. That is exactly what I needed!