Help deleting row

  • Thread starter Ashley via OfficeKB.com
  • Start date
A

Ashley via OfficeKB.com

I don't know what's wrong!! I'm trying to delete an entire row if the word
CLOSED is found in column U here's what I have but it doesn't do anything

Dim Lastrow As Long
Dim row_index As Long
Application.ScreenUpdating = False
lastrow = ActiveSheet.Cells(Rows.Count, 21).End xlUp).Row
For row_index = lastrow -21 To 21 Step -21
If Cells(row_index,21). Value = "CLOSED" Then
Rows(row_index).Delete
End If
Next
Application.ScreenUpdating = True
End Sub
 
D

Dave Peterson

There are a lot of 21's in that code...

Did you really mean to step in groups of 21? Did you want to start from the
lastrow -21?

Maybe.....

Option Explicit
Sub Testme()
Dim Lastrow As Long
Dim row_index As Long
Application.ScreenUpdating = False
lastrow = ActiveSheet.Cells(Rows.Count, 21).End xlUp).Row
For row_index = lastrow To 1 Step -1
If ucase(Cells(row_index,21).Value) = "CLOSED" Then
Rows(row_index).Delete
End If
Next row_index
Application.ScreenUpdating = True
End Sub

This looks at each row (step -1) and deletes the row if closed is in column 21
(U).

ps. You may want to copy directly from the code window and paste into the
message--just to make sure typos aren't added to your sample code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top