Delete row macro

A

AT

Hi,
I need a macro that can delete certain rows as follows:
If B(X)=B(X+1) AND C(X)=C(X+1) AND D(X) =0 THEN
Delete row(X)
Else do nothing

Is it possible?
 
M

Mike H

Hi,

The logic fior this interprets as
If B1 = B2 And C1 = C2 And D1 = 0 Then
delete the row so try this

Sub delete_Me()
Lastrow = Cells(Cells.Rows.Count, "B").End(xlUp).Row
For x = Lastrow To 1 Step -1
If Range("B" & (x)) = Range("B" & (x + 1)) _
And Range("C" & (x)) = Range("C" & (x + 1)) _
And (Range("D" & (x))) = "0" Then
Rows(x).Delete
End If
Next
End Sub

Mike
 
A

AT

Thanks.
Worked fine!

Mike H said:
Hi,

The logic fior this interprets as
If B1 = B2 And C1 = C2 And D1 = 0 Then
delete the row so try this

Sub delete_Me()
Lastrow = Cells(Cells.Rows.Count, "B").End(xlUp).Row
For x = Lastrow To 1 Step -1
If Range("B" & (x)) = Range("B" & (x + 1)) _
And Range("C" & (x)) = Range("C" & (x + 1)) _
And (Range("D" & (x))) = "0" Then
Rows(x).Delete
End If
Next
End Sub

Mike
 

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