ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   macro to delete a row based on criteria (https://www.excelbanter.com/excel-programming/417724-macro-delete-row-based-criteria.html)

aileen

macro to delete a row based on criteria
 
I have a document with 6 columns of data and an unspecified number of rows.
I would like a macro to delete any row that has both columns 5 and 6 equal to
0. I would then need every other row to move up or down so there are no blank
rows.

JLGWhiz

macro to delete a row based on criteria
 
Untested but should work.

Sub delRws()
Dim lr As Long, i As Long
lr = ActiveSheet.Cells(Rows.Count, 5).End(xlUp).Row
For i = lr To 2 Step -1
With ActiveSheet
If .Cells(i, 5) = 0 And .Cells(i, 6) = 0 Then
.Cells(i, 1).EntireRow.Delete
End If
End With
Next
End Sub

"aileen" wrote:

I have a document with 6 columns of data and an unspecified number of rows.
I would like a macro to delete any row that has both columns 5 and 6 equal to
0. I would then need every other row to move up or down so there are no blank
rows.


Bob Phillips[_3_]

macro to delete a row based on criteria
 
Public Sub ProcessData()
Dim i As Long
Dim LastRow As Long

With ActiveSheet

LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = LastRow To 1 Step -1

If .Cells(i, "E").Value = 0 And .Cells(i, "F").Value = 0 Then

.Rows(i).Delete
End If
Next i
End With

End Sub

--
__________________________________
HTH

Bob

"aileen" wrote in message
...
I have a document with 6 columns of data and an unspecified number of rows.
I would like a macro to delete any row that has both columns 5 and 6 equal
to
0. I would then need every other row to move up or down so there are no
blank
rows.




aileen

macro to delete a row based on criteria
 
Both of those worked. Thanks so much.

"Bob Phillips" wrote:

Public Sub ProcessData()
Dim i As Long
Dim LastRow As Long

With ActiveSheet

LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = LastRow To 1 Step -1

If .Cells(i, "E").Value = 0 And .Cells(i, "F").Value = 0 Then

.Rows(i).Delete
End If
Next i
End With

End Sub

--
__________________________________
HTH

Bob

"aileen" wrote in message
...
I have a document with 6 columns of data and an unspecified number of rows.
I would like a macro to delete any row that has both columns 5 and 6 equal
to
0. I would then need every other row to move up or down so there are no
blank
rows.






All times are GMT +1. The time now is 08:46 AM.

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