Macro to remove duplicates

Alex O

Active Member
Joined
Mar 16, 2009
Messages
345
Office Version
  1. 365
Platform
  1. Windows
Need help with a macro that will identify duplicates in C & E and keep first instance of duplicate. So my example below would look like:
24/7 Shield Security & More 6 1441.82<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
24/7 Shield Security & More 6 1231.98

Any help would be appreciated.<o:p></o:p>


<TABLE style="BACKGROUND-COLOR: #ffffff; PADDING-LEFT: 2pt; PADDING-RIGHT: 2pt; FONT-FAMILY: Arial,Arial; FONT-SIZE: 10pt" border=1 cellSpacing=0 cellPadding=0><COLGROUP><COL style="WIDTH: 30px; FONT-WEIGHT: bold"><COL style="WIDTH: 288px"><COL style="WIDTH: 143px"><COL style="WIDTH: 121px"></COLGROUP><TBODY><TR style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt; FONT-WEIGHT: bold"><TD> </TD><TD>C</TD><TD>D</TD><TD>E</TD></TR><TR style="HEIGHT: 17px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">2360</TD><TD style="TEXT-ALIGN: left">2012 Cafe</TD><TD style="TEXT-ALIGN: left">34</TD><TD style="TEXT-ALIGN: left">292</TD></TR><TR style="HEIGHT: 17px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">2361</TD><TD style="TEXT-ALIGN: left">21st Century Realty Services</TD><TD style="TEXT-ALIGN: left">6</TD><TD style="TEXT-ALIGN: left">1733.92</TD></TR><TR style="HEIGHT: 17px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">2362</TD><TD style="TEXT-ALIGN: left; BACKGROUND-COLOR: #ff0000">24/7 Shield Security & More</TD><TD style="TEXT-ALIGN: left">6</TD><TD style="TEXT-ALIGN: left; BACKGROUND-COLOR: #ff0000">1441.82</TD></TR><TR style="HEIGHT: 17px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">2363</TD><TD style="TEXT-ALIGN: left; BACKGROUND-COLOR: #ff0000">24/7 Shield Security & More</TD><TD style="TEXT-ALIGN: left">6</TD><TD style="TEXT-ALIGN: left; BACKGROUND-COLOR: #ff0000">1231.98</TD></TR><TR style="HEIGHT: 17px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">2364</TD><TD style="TEXT-ALIGN: left; BACKGROUND-COLOR: #ff0000">24/7 Shield Security & More</TD><TD style="TEXT-ALIGN: left">6</TD><TD style="TEXT-ALIGN: left; BACKGROUND-COLOR: #ff0000">1231.98</TD></TR><TR style="HEIGHT: 17px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">2365</TD><TD style="TEXT-ALIGN: left">3 C Solutions LTD</TD><TD style="TEXT-ALIGN: left">6</TD><TD style="TEXT-ALIGN: left">1444.15</TD></TR></TBODY></TABLE>
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Try with a copy of your sheet

Code:
Sub test()
Dim LR As Long, i As Long
LR = Range("C" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
    If Range("C" & i).Value = Range("C" & i - 1).Value And Range("E" & i).Value = Range("E" & i - 1).Value Then Rows(i).Delete
Next i
End Sub
 
Upvote 0
Or, if you're using Excel 2007 or later (tested on Excel 2010)...

Code:
[font=Courier New][color=darkblue]Sub[/color] RemoveDuplicates()

    [color=darkblue]With[/color] Range("C1", Cells(Rows.Count, "E").End(xlUp))
        .RemoveDuplicates Columns:=Array(1, 3), Header:=xlGuess
    [color=darkblue]End[/color] [color=darkblue]With[/color]
    
[color=darkblue]End[/color] [color=darkblue]Sub[/color][/font]
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,723
Members
452,939
Latest member
WCrawford

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