Deleting multiple rows within a spreadsheet

J

Jeff

Good day all,

I am merging lots of data together from other sheets and i need to
clean it up. i have written a formula so when there is no data that
matches the defined parameters, "delete" is inserted. now i want to
delete the rows that contain "delete" in col "F". how do i do this?

Your help in this matter would be greatly appreciated,

Regards
Jeff Priest
 
T

Tom Ogilvy

Dim i as long
Dim lastRow as long
lastrow = Cells(rows.count,"F").End(xlup).row
for i = lastrow to 1 step - 1
if lcase(cells(i,"F").Value) = "delete" then
cells(i,"F").EntireRow.Delete
end if
Next
 
R

Ron de Bruin

Try this one

For more example code see
http://www.rondebruin.nl/delete.htm

Sub Example1()
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

Firstrow = ActiveSheet.UsedRange.Cells(1).Row
Lastrow = ActiveSheet.UsedRange.Rows.Count + Firstrow - 1
With ActiveSheet
.DisplayPageBreaks = False
For Lrow = Lastrow To Firstrow Step -1
If IsError(.Cells(Lrow, "F").Value) Then
'Do nothing, This avoid a error if there is a error in the cell

ElseIf .Cells(Lrow, "F").Value = "delete" Then .Rows(Lrow).Delete
'This will delete each row with the Value "delete" in Column F, case sensitive.

End If
Next
End With
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub
 
Top