Compare and Remove Duplicates between Two Excel Sheets

I know how to create a macro to delete dups on the same sheet, but I need one to remove from different sheets.

I have two identical sheets, but I need them to stay seperate.  I would like to to compare Sheet One to Sheet Two using columns B, C, D K.  If there are duplicates, I would like them removed from Sheet One Only.

I would like this done using VBA.
kateebebeAsked:
Who is Participating?
 
nutschConnect With a Mentor Commented:
Do you know how to record macros? I'd run a macro to add a formula columns with a COUNTIFS formula in sheet1 (to catch duplicates), then do an autofilter to remove the duplicate rows.

Something like the following:

Sub Macro1()
    
Dim lCol As Long
Dim lLastRow As Long, lRowLoop As Long, lLastRowSheet2 As Long

lCol = Sheets("Sheet1").Cells(1, Columns.Count).End(xlToLeft).Column
    
lLastRow = Sheets("Sheet1").Cells(Rows.Count, "B").End(xlUp).Row

lLastRowSheet2 = Sheets("Sheet2").Cells(Rows.Count, "B").End(xlUp).Row

With Sheets("Sheet1")
    .Range(.Cells(2, lCol), .Cells(lLastRow, lCol)).FormulaR1C1 = "=COUNTIFS(Sheet2!R1C2:R" & lLastRowSheet2 & "C2,RC2," & _
                                                                            "Sheet2!R1C3:R" & lLastRowSheet2 & "C3,RC3," & _
                                                                            "Sheet2!R1C4:R" & lLastRowSheet2 & "C4,RC4," & _
                                                                            "Sheet2!R1C11:R" & lLastRowSheet2 & "C11,RC11)"
    
    
    
    .Range(.Cells(2, lCol), .Cells(lLastRow, lCol)).NumberFormat = "0"
    
    With .Cells(1, 1).CurrentRegion
        .AutoFilter Field:=lCol, Criteria1:=">0"
        .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
        .AutoFilter
    End With
    
    .Range(.Cells(2, lCol), .Cells(lLastRow, lCol)).ClearContents
End With

End Sub

Open in new window

0
 
kateebebeAuthor Commented:
Thank you for the alternative idea for how to do this.  Makes sense.  Thank you.

I actually ended up creating a crude formula that was =b2&c2&d2&k2 in each sheet, then a 2nd formula (vlookup with the word "Duplicate") on my main page that compared the two based on that cell and then I ran a delete rows macro based off the results.

Was hoping there was an easy way to compare the two and delete duplicates and this way is pretty crude, but at the end of the day, it did the job I guess.

Thanks for your help.
0
 
nutschCommented:
Do you need additional help at this stage, or are you fine with current state of things?

Thomas
0
 
kateebebeAuthor Commented:
My apologies.  I thought I had accepted your solution already.
0
 
nutschCommented:
No problem, have fun coding

Thomas
0
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.

All Courses

From novice to tech pro — start learning today.