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
Special 175377.2 QG #LDP 2443 #AVP 4748
Quantity
ECEPI4431
EPILZ7501031
ESI6AV21232DB030AX01
ESI6ES72151AG400XB01
ESI6ES72231BL320XB02
ESI6ES79548LC020AA01
EDATTHQQS001
Special 175427 QG #LDP 2442 #AVP 4726
Quantity
ECEBGS86251
ECEOCM50100BB071
EPILZ7501031
ESI3LD22130TK511
ESI6ES72151AG400XB01
ESI6ES72231BL320XB01
ESI6ES79548LC020AA01
ESI6AV21232DB030AX01
ETMXB4BVB61
Special 175364 BD #LDP 2441 #AVP 4740
Quantity
ETMA9F791021
Special 175364 QG #LDP 2439 #AVP 4751
Quantity
Special 175346 QG #LDP 2438 #AVP 4750
Quantity
ECEOCM50100BB071
EPILZ7501031
ESI3LD22130TK511
ESI6ES72151AG400XB01
ESI6ES72231BL320XB01
ESI6ES79548LC020AA01
ESI6AV21232DB030AX01
ETMXB4BVB61
Special 175364 BD #LDP 2441 #AVP 4740
Quantity
Special 175364 QG #LDP 2439 #AVP 4751
Quantity
Special 175346 QG #LDP 2438 #AVP 4750
Quantity
GIA IN ORDINE DA UFFICIO TECNICO - NON SERVE ORDINARE!!!Quantity

<colgroup><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
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,215,562
Messages
6,125,546
Members
449,237
Latest member
Chase S

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