View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
J.W. Aldridge J.W. Aldridge is offline
external usenet poster
 
Posts: 425
Default Delete all rows except

Was given this code, but doesnt work. It deletes everything.
The data on the worksheet was imported - i think this has something to
do with the reason it doesnt work (or filter) properly.

Sub DeleteRows()


Dim LastRow As Long
Dim rw As Long


Application.ScreenUpdating = False


LastRow = Cells(Rows.Count, "B").End(xlUp).Row


For rw = LastRow To 2 Step -1
If Cells(rw, "B").Value < "Apples" Or Cells(rw, "B").Value
<
"Oranges" Then
Rows(rw).Delete Shift:=xlUp
End If
Next rw


Application.ScreenUpdating = True


End Sub