Excel Duplicates in File

Tech Analysts,

Looking for a SubRoutine that can help:
1  Identify duplicates in the attached file
     Count duplicates

2   Combine Lines that are duplicates....  in a a different worksheet
Elections-looking-for-dups-10192015.xlsx
AyansaneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongCommented:
first of all, how do you define "duplicates" ? which columns are used for comparison?
0
Ryan ChongCommented:
if you wish to compare all 5 columns to identify the duplicate entries, you probably can use CountIFS formula for identification.

For example, in Cell F2, put in formula:
=COUNTIFS($A:$A,"="&A2,$B:$B,"="&B2,$C:$C,"="&C2,$D:$D,"="&D2,$E:$E,"="&E2)

Open in new window

and drag down the formula accordingly.

By using this formula, you will find the count of occurrence per item. If the value is greater than 1 then it's identified as duplicate.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ryan ChongCommented:
to copy the duplicate rows to another sheet, you probably need this:
Sub copyDupRows()
    Dim lastRow As Long
    Dim r As Range
    Dim ws As Worksheet
    
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    
    ActiveSheet.Copy After:=Sheets(Sheets.Count)
    Set ws = Sheets(Sheets.Count)
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
    
    ws.Range("$F$2:$F$" & lastRow).Cells.FormulaR1C1 = _
        "=COUNTIFS(C1,""=""&RC[-5],C2,""=""&RC[-4],C3,""=""&RC[-3],C4,""=""&RC[-2],C5,""=""&RC[-1])"
    ws.Range("$A$1:$F$" & lastRow).AutoFilter Field:=6, Criteria1:="=1", _
        Operator:=xlOr, Criteria2:="="
    
    Set r = ws.Range("A2:A" & lastRow).SpecialCells(xlCellTypeVisible)
    r.EntireRow.Delete
    ws.Columns("F").EntireColumn.Delete
    ws.AutoFilterMode = False
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub

Open in new window

Elections-looking-for-dups-10192015.xlsm
0
AyansaneAuthor Commented:
Hey Ryan,

It seems that we are comparing two sets of rows each time...
Can we get it to highlight the duplicate..?

Also, your final subset has only "four" lines.. on the new sheet .  What are those..?  Thx

Best,
Hans
0
Ryan ChongCommented:
To highlight the duplicate entries, you probably can use Conditional Formatting with following formula:
=COUNTIFS($A:$A,"="&INDIRECT("A"&ROW()),$B:$B,"="&INDIRECT("B"&ROW()),$C:$C,"="&INDIRECT("C"&ROW()),$D:$D,"="&INDIRECT("D"&ROW()),$E:$E,"="&INDIRECT("E"&ROW()))>1

Open in new window


>>Also, your final subset has only "four" lines.. on the new sheet .  What are those..?
what do you mean by that?
Elections-looking-for-dups-10192015.xlsm
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.