Modify a Delete Duplicate Macro?

jwasten

Board Regular
Joined
May 29, 2002
Messages
90
I have a macro which deletes duplicate rows if the data in Column A is the same. Is there a macro to delete duplicate rows (keeping the last row for each duplicate) when the data in BOTH Column A and Column B (information in other columns will vary) are the same? The macro I'm using now (which I received from this forum) for deleting duplicates when only Column A is the same is as follows -
rowx=1
Do Until Cells(rowx+1,1).Value=""
If UCase(Cells(rowx,1).Value)=UCase(Cells(rowx+1,1).Value) Then
Cells(rowx+1,1).EntireRow.Delete
Else
rowx=rowx+1
End If
Loop

Beep

End Sub

Is there a way to adjust the macro so it checks cells in both Column A and Column B and deletes the rows if the information in those cells are duplicates?

Thanks!
 

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.
Think this should so what you want.
As I understand it you want to check that A1=A2 and that B1=B2 (not that A1=A2=B1=B2) and in this case delete the row.

Sub DeleteEm()
Range("a1").Select
Do While ActiveCell.Value <> ""
If ActiveCell.Value = ActiveCell.Offset(1, 0).Value Then
If ActiveCell.Offset(0, 1).Value = ActiveCell.Offset(1, 1) Then
ActiveCell.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
Else
ActiveCell.Offset(1, 0).Select
End If
Loop
End Sub

HTH
 
Upvote 0

Forum statistics

Threads
1,213,563
Messages
6,114,329
Members
448,564
Latest member
ED38

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