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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

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