Duplicates using macro

weskyleo

New Member
Joined
Apr 9, 2011
Messages
8
Somewhere I found the following to figure out the duplicates in a col but don't quite understand how it works
=IF(MAX(COUNTIF(K2:K9,K2:K9))>1,"Duplicate","No Duplicate")

Here the data is in the range K2:K9 which might have some duplicate entries. I guess I need help understanding COUNTIF's second parameter as a range of reference

Any help is appreciated

thanks
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Not sure what you want accomplished without some sort of data layout of your sheet.

Here's my take on it:
Sheet1

<TABLE style="BACKGROUND-COLOR: #ffffff; PADDING-LEFT: 2pt; PADDING-RIGHT: 2pt; FONT-FAMILY: Calibri,Arial; FONT-SIZE: 11pt" border=1 cellSpacing=0 cellPadding=0><COLGROUP><COL style="WIDTH: 30px; FONT-WEIGHT: bold"><COL style="WIDTH: 64px"><COL style="WIDTH: 64px"></COLGROUP><TBODY><TR style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt; FONT-WEIGHT: bold"><TD> </TD><TD>K</TD><TD>L</TD></TR><TR style="HEIGHT: 22px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">1</TD><TD style="TEXT-ALIGN: center">1</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Duplicate</TD></TR><TR style="HEIGHT: 22px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">2</TD><TD style="TEXT-ALIGN: center">2</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Duplicate</TD></TR><TR style="HEIGHT: 22px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">3</TD><TD style="TEXT-ALIGN: center">3</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">No Duplicate</TD></TR><TR style="HEIGHT: 22px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">4</TD><TD style="TEXT-ALIGN: center">4</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">No Duplicate</TD></TR><TR style="HEIGHT: 22px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">5</TD><TD style="TEXT-ALIGN: center">8</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">No Duplicate</TD></TR><TR style="HEIGHT: 22px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">6</TD><TD style="TEXT-ALIGN: center">1</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Duplicate</TD></TR><TR style="HEIGHT: 22px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">7</TD><TD style="TEXT-ALIGN: center">2</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Duplicate</TD></TR><TR style="HEIGHT: 22px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">8</TD><TD style="TEXT-ALIGN: center">10</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">No Duplicate</TD></TR><TR style="HEIGHT: 22px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">9</TD><TD style="TEXT-ALIGN: center">7</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">No Duplicate</TD></TR></TBODY></TABLE>

Excel tables to the web >> http://www.excel-jeanie-html.de/index.php?f=1" target="_blank"> Excel Jeanie HTML 4


Formula in L1 copied down:
=IF((COUNTIF($K$1:$K$9,$K$1:$K$9))>1,"Duplicate","No Duplicate")

Edit: Ooops - just saw that your data starts in row 2. Just adjust the formula to suit.
 
Last edited:
Upvote 0
That still doesnt explain what is meant by the cell reference in the second parameter of COUNTIF
=IF(MAX(COUNTIF(K2:K9,K2:K9))>1,"Duplicate","No Duplicate")

The formula tells you the entries that are duplicated in a col(sortof macro version of remove duplicates which tells you whats duplicated and gives you and opportunity to view and manually remove)

You should see the following result

shaa Duplicate
shaa No Duplicate
yuu No Duplicate
yii No Duplicate
timm Duplicate
timm Duplicate
tim No Duplicate
him No Duplicate
timm No Duplicate
 
Upvote 0
Somewhere I found the following to figure out the duplicates in a col but don't quite understand how it works
=IF(MAX(COUNTIF(K2:K9,K2:K9))>1,"Duplicate","No Duplicate")

Here the data is in the range K2:K9 which might have some duplicate entries. I guess I need help understanding COUNTIF's second parameter as a range of reference

Any help is appreciated

thanks

Hope this helps
Excel Workbook
KLMNO
1Brokendown to components
2ListFormulacountingcheck for Max countResult
3CarDuplicate2TRUEDuplicate
4HouseDuplicate2TRUEDuplicate
5BoatDuplicate2TRUEDuplicate
6CarDuplicate2TRUEDuplicate
7HouseDuplicate2TRUEDuplicate
8BoatDuplicate2TRUEDuplicate
9ComputerNo duplicate1FALSENo Duplicate
10BookNo duplicate1FALSENo Duplicate
Sheet1
 
Upvote 0
This is not the answer I'm getting. Removing duplicates from your answer will get rid of Car, House and Boat completely. My solution removes only the duplicate ones. So one time those entries should be present
Like the ans below

Car Duplicate
House Duplicate
Boat Duplicate
Car No Duplicate
House No Duplicate
Boat No Duplicate
computer No Duplicate
Book No Duplicate

Sorting and filtering on No Duplicates results in Car, House, Boat, Computer and Book . Did you miss something?
 
Upvote 0
The goal is to write a macro and identify and remove duplicates. Using advanced filter/remove duplicates features are inbuilt . The idea is not to use them

Regardless of what I have found (listed above) , can someone answer how to write this macro?
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,734
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