Remove duplicate rows

mlbarry

New Member
Joined
Sep 26, 2012
Messages
47
I have two spread sheets that I combine. One is openinvoices and the other is payments, so I have a spread sheet with all open invoicesand payments for invoices that were paid that day. Is there a way to remove theinvoices that were paid without having to go through and select every line anddelete the rows manually? So I have column B (invoice #) and column D (invoice/payment$) if these two match exactly I want these rows removed, there may be severhundred that meet this requirement on this spread sheet.

Customer NameInvoice #DateAmount
AAA10015/1/13$500.00
1001$500.00
BBB10026/1/13$450.00
CCC10037/1/13$250.00
DDD10046/15/13$100.00

<tbody>
</tbody>
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Code:
Sub a()
LR = Cells(Rows.Count, "A").End(xlUp).Row
For r = LR To 2 Step -1
  If Cells(r, 2) = Cells(r - 1, 2) And Cells(r, 4) = Cells(r - 1, 4) Then
    Rows(r).Delete
  End If
Next
End Sub
 
Upvote 0
I had to change the column numbers (below) because the accrual spread sheet is Invoice # (Column D) and Invoiced / Paid (Column K) but it only removed one of the rows (it removed the highlighted yellow only) and I need to remove both the invoice and payment only if they equal. In the below example I would need to remove row 3 & 4.

Sub a()
LR = Cells(Rows.Count, "A").End(xlUp).Row
For r = LR To 4 Step -1
If Cells(r, 4) = Cells(r - 1, 4) And Cells(r, 11) = Cells(r - 1, 11) Then
Rows(r).Delete
End If
Next
End Sub

ABCDEFGHIJK
1CustomerPONameInvoice #xxxxInvoice DatexxxxxxxxxxxxxxxxInvoiced / Paid
2DDD500DDD10043/3/13$900.00
3AAA200AAA10011/1/13$300.00
41001$300.00
5BBB300BBB10022/1/13$600.00
6CCC400CCC10033/1/13$900.00

<tbody>
</tbody>
 
Upvote 0
Code:
Sub a()
LR = Cells(Rows.Count, "A").End(xlUp).Row
For r = LR To 2 Step -1
  If Cells(r, 4) = Cells(r - 1, 4) And Cells(r, 11) = Cells(r - 1, 11) Then
    Rows(r).Delete
    Rows(r-1).Delete
   End If
Next
End Sub
 
Last edited:
Upvote 0
One more thing. We also have discounts taken, in the example above discounts would be in column J, so if J4 + K4 = the total in K3 and D3 and D4 equal then delete both rows 3 and 4
 
Upvote 0
Code:
Sub a() 
LR = Cells(Rows.Count, "A").End(xlUp).Row
 For r = LR To 2 Step -1
   If Cells(r, 4) = Cells(r - 1, 4) And Cells(r, 11) = Cells(r - 1, 11) Then     
     Rows(r).Delete
     Rows(r-1).Delete 
   End If
   If Cells(r, 10) + Cells(r, 10) = Cells(r - 1, 11) And Cells(r, 4) = Cells(r - 1, 4) Then     
     Rows(r).Delete
     Rows(r-1).Delete 
   End If
 Next
 End Sub
 
Upvote 0
I get an error message on:
If Cells(r, 10) + Cells(r, 10) = Cells(r - 1, 11) And Cells(r, 4) = Cells(r - 1, 4) Then


I've run the first part of the macro and it takes a very long time, about 1.5 hours. I have over 4000 line items in a table. Do you have any sujestions?
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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