Try this one
More info on this page
http://www.rondebruin.nl/delete.htm
Sub Loop_Example()
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
Dim ArrNames As Variant
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
'We use the ActiveSheet but you can replace this with
'Sheets("MySheet")if you want
With ActiveSheet
'We select the sheet so we can change the window view
.Select
'If you are in Page Break Preview Or Page Layout view go
'back to normal view, we do this for speed
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
'Turn off Page Breaks, we do this for speed
.DisplayPageBreaks = False
'Set the first and last row to loop through
Firstrow = .UsedRange.Cells(1).Row
Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
'array with names that we want to keep
ArrNames = Array("Agt", "Agent")
'We loop from Lastrow to Firstrow (bottom to top)
For Lrow = Lastrow To Firstrow Step -1
'We check the values in the A column in this example
With .Cells(Lrow, "A")
If Not IsError(.Value) Then
If IsError(Application.Match(.Value, ArrNames, 0)) Then .EntireRow.Delete
End If
End With
Next Lrow
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub
--
Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm
"fpd833" wrote in message ...
I am working with a large data sample that is in a horrible format. It
includes a lot of rows of data that I do not need, and is in a format that no
simple sorting or filtering will not work to give me just the data I want.
Can anyone help me with some code to delete all rows that do not have "Agt"
or "Agent" in column A? If this is possible I would look for this to happen
in rows 6 through 5000.
Thank you in advance for your help!
Ken