ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help deleting row (https://www.excelbanter.com/excel-programming/385670-help-deleting-row.html)

Ashley via OfficeKB.com

Help deleting row
 
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

--
Message posted via http://www.officekb.com


Dave Peterson

Help deleting row
 
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.



"Ashley via OfficeKB.com" wrote:

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

--
Message posted via http://www.officekb.com


--

Dave Peterson


All times are GMT +1. The time now is 04:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com