Macro to find duplicates and display non-duplicates in different sheet

tacosauce31

New Member
Joined
Aug 30, 2017
Messages
6
I'm looking to build a macro that will find duplicates from two different ranges on two different sheets. The data I'd like to compare is usually on column E on both worksheets. I would like the macro to also display non-duplicates on a new sheet.

Can I have some help on this?

Thank you!
 
mse330,

I've debugged the code line by line and it works until the very last line of code. It somehow does not remove all the duplicates. I don't know if that helps.
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
I removed the two statements from mse330's code inserted the following code to get the results I needed:


Code:
Dim Cell as Range
Dim DSO as Object
Dim DstRng as Range
Dim Key as Variant
Dim RngEnd as Range
Dim SrcRng as Range
Dim Wks as Worksheet

'Set the ranges on the worksheet
Set DstRng = Wks.Range("D1")
Set SrcRng = Wks.Range("A1")


'Determine the SrcRng size
Set RngEnd = Wks.Cells(Rows.Count, SrcRng.Column).End(xlUp)
Set SrcRng = IIf(RngEnd.Row < SrcRng.Row, SrcRng, Wks.Range(SrcRng, RngEnd))


'Clear the desintation range
Set RngEnd = Wks.Cells(Rows.Count, DstRng.Column).End(xlUp)
Set DstRng = IIf(RngEnd.Row < DstRng.Row, DstRng, Wks.Range(DstRng, RngEnd))
DstRng.ClearContents


'Create the Dictionary Object
Set DSO = CreateObject("Scripting.Dictionary")
'Set text comparisons not to be case sensitive
DSO.CompareMode = vbTextCompare


'Save each entry along with the number of times it occurs
For Each Cell In SrcRng
    Key = Trim(Cell.Value)
    If Key <> "" And Not DSO.Exists(Key) Then
        DSO.Add Key, 1
    Else
        DSO(Key) = DSO(Key) + 1
    End If
Next Cell


'List only entries that appear once
For Each Key In DSO.Keys
    If DSO(Key) = 1 Then
        R = R + 1
        DstRng.Cells(R, 1) = Key
    End If
Next Key


'Release the object and memory it uses
Set DSO = Nothing
Thank you guys so much for your help!
 
Upvote 0
tacosauce31, have you tried the code provided by Fluff in post #10 ?
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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