delete entire row on contiguous duplicates

ninez87

New Member
Joined
Aug 5, 2017
Messages
7
hi need help for a look that do

Run a loop cycle that searches for the word "Special" in column A1 (the cell a1 contains different words inside)
If true looking if b2 = "Quantity" deletes b1 row)


in red is what i need to be deleted
Thanks for help


A B
[TABLE="width: 464"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD]Special 175377.2 QG #LDP 2443 #AVP 4748
[/TD]
[TD]Quantity
[/TD]
[/TR]
[TR]
[TD]ECEPI443[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]EPILZ750103[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]ESI6AV21232DB030AX0[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]ESI6ES72151AG400XB0[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]ESI6ES72231BL320XB0[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]ESI6ES79548LC020AA0[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]EDATTHQQS00[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]Special 175427 QG #LDP 2442 #AVP 4726
[/TD]
[TD]Quantity
[/TD]
[/TR]
[TR]
[TD]ECEBGS8625[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]ECEOCM50100BB07[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]EPILZ750103[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]ESI3LD22130TK51[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]ESI6ES72151AG400XB0[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]ESI6ES72231BL320XB0[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]ESI6ES79548LC020AA0[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]ESI6AV21232DB030AX0[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]ETMXB4BVB6[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]Special 175364 BD #LDP 2441 #AVP 4740
[/TD]
[TD]Quantity
[/TD]
[/TR]
[TR]
[TD]ETMA9F79102[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]Special 175364 QG #LDP 2439 #AVP 4751
[/TD]
[TD]Quantity
[/TD]
[/TR]
[TR]
[TD]Special 175346 QG #LDP 2438 #AVP 4750
[/TD]
[TD]Quantity
[/TD]
[/TR]
[TR]
[TD]ECEOCM50100BB07[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]EPILZ750103[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]ESI3LD22130TK51[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]ESI6ES72151AG400XB0[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]ESI6ES72231BL320XB0[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]ESI6ES79548LC020AA0[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]ESI6AV21232DB030AX0[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]ETMXB4BVB6[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]Special 175364 BD #LDP 2441 #AVP 4740
[/TD]
[TD]Quantity
[/TD]
[/TR]
[TR]
[TD]Special 175364 QG #LDP 2439 #AVP 4751
[/TD]
[TD]Quantity
[/TD]
[/TR]
[TR]
[TD]Special 175346 QG #LDP 2438 #AVP 4750
[/TD]
[TD]Quantity
[/TD]
[/TR]
[TR]
[TD]GIA IN ORDINE DA UFFICIO TECNICO - NON SERVE ORDINARE!!![/TD]
[TD]Quantity
[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
The color codining is a little confusing, but give this a try.
Code:
Sub deleStuff()
Dim i As Long
    With ActiveSheet
        For i = .Cells(Rows.Count, 2).End(xlUp).Row To 2 Step -1
            If LCase(.Cells(i, 2).Value) = "quantity" And InStr(.Cells(i, 1), "Special") = 1 _
            And InStr(.Cells(i - 1, 1), "Special") = 1 Then
                .Rows(i).Delete
            End If
        Next
    End With
End Sub
Make a back up copy of your file to test this code on. Do not test it on your original file until you know it works.
 
Upvote 0
thanks for reply

tried but not work
not deleting rows , no error given


The color codining is a little confusing, but give this a try.
Code:
Sub deleStuff()
Dim i As Long
    With ActiveSheet
        For i = .Cells(Rows.Count, 2).End(xlUp).Row To 2 Step -1
            If LCase(.Cells(i, 2).Value) = "quantity" And InStr(.Cells(i, 1), "Special") = 1 _
            And InStr(.Cells(i - 1, 1), "Special") = 1 Then
                .Rows(i).Delete
            End If
        Next
    End With
End Sub
Make a back up copy of your file to test this code on. Do not test it on your original file until you know it works.
 
Upvote 0
thanks for reply

tried but not work
not deleting rows , no error given

OK, I used your example data in the OP to test the macro and it worked on that. Don't know why it isn't working for you.
 
Upvote 0
in red is what i need to be deleted
Near the bottom of your sample table, can you explain why 3 "Special ..." cells are red but only 1 of the "Quantity" cells is red?
 
Last edited:
Upvote 0
@ninez87, try this modified version and see if it deletes the rows.

Code:
Sub deleStuff2()
Dim i As Long
    With ActiveSheet
        For i = .Cells(Rows.Count, 2).End(xlUp).Row To 2 Step -1
            If LCase(.Cells(i, 2).Value) = "quantity" And InStr(.Cells(i, 1), "Special") > 0 _
            And InStr(.Cells(i - 1, 1), "Special") > 0 Then
                .Rows(i).Delete
            End If
        Next
    End With
End Sub

This checks to see if 'Special' is anywhere in the column A Text. I didn't want to use that originally because I don't know what your total data looks like, but if there are leading spaces preventing the original code from working like you want, then this should fix that.
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top