Re: VB Delete Rows

  • Thread starter Thread starter Frank Kabel
  • Start date Start date
F

Frank Kabel

Hi
reason for this error is:
you start in row 1 but you're trying to move the cursor one row up (row
0).
Also you should start in the last row moving up

You may try the following code instead:

Sub delete_rows()
Dim RowNdx As Long
Dim LastRow As Long
Application.ScreenUpdating = False
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).row
For RowNdx = LastRow To 1 Step -1
with Cells(RowNdx, "A")
if .value<>"A" and .value <>"B" and .value <>"C" then
Rows(RowNdx).Delete
End If
end with
Next RowNdx
Application.ScreenUpdating = True
End Sub





--
Regards
Frank Kabel
Frankfurt, Germany

dhbyrne said:
I am trying (badly) to modify the code below which i was using for
another task. I want it to delete the row only if the value in Column B
is not A, B of E. (groups) If the value is anything else then delete
the row and move onto the next one
When the Code gets to Set c = cf.Offset(-1, 0) etc it creates an
error "application defined, or object defined error". I was trying to
use the help to fix the problem but as usual it was no help.
 
Back
Top