Remove Duplicate Macro

DRExcel515

Board Regular
Joined
Oct 20, 2017
Messages
56
I have a spreadsheet that lists a set of identifiers (142182) in column "F" that every month I copy and paste into another tab labled "DISTINCT", which I then do the remove duplicates process. Is there a way to use a macro to say from these four tabs (CRO ICO SICEHY and SICCRO) take column F (disregarding the header in F1) and paste only non-duplicate values into these four tabs (CROMV ICOMV SICEHYMV and SICCROMV) in column A (starting in A2 on the tabs as to leave the header in tact)?



<tbody>
</tbody>
Thank you in advance for any advice/help!

 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Re: Remove Duplicate Macro Help

How about
Code:
Sub CopyPasteDuplicates()

   Dim Shts As String
   Dim Ary As Variant
   Dim Cnt As Long
   Dim Cl As Range
   Dim Dic As Object
   
   Shts = "CRO|CROMV|ICO|ICOMV|SICEHY|SICEHYMV|SICCRO|SICCROMV"
   Ary = Split(Shts, "|")
   
   Set Dic = CreateObject("scripting.dictionary")
      For Cnt = LBound(Ary) To UBound(Ary) Step 2
         With Sheets(Ary(Cnt))
            For Each Cl In .Range("F2", .Range("F" & Rows.Count).End(xlUp))
               If Not Dic.exists(Cl.Value) Then Dic.Add Cl.Value, Nothing
            Next Cl
            Sheets(Ary(Cnt + 1)).Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(Dic.Count).Value = _
               Application.Transpose(Dic.keys)
            Dic.removeall
         End With
      Next Cnt

End Sub
 
Upvote 0
Re: Remove Duplicate Macro Help

Thank you so much! This works perfectly except for one small issue (that I forgot to mention). Is it possible to incorporate into this code that for the tabs CRO and ICO to disregard the identifier in column F only if in column L the security type says Reserves

<tbody>
</tbody>
 
Upvote 0
Re: Remove Duplicate Macro Help

How about
Code:
Sub CopyPasteDuplicates()

   Dim Shts As String
   Dim Ary As Variant
   Dim Cnt As Long
   Dim Cl As Range
   Dim Dic As Object
   
   Shts = "CRO|CROMV|ICO|ICOMV|SICEHY|SICEHYMV|SICCRO|SICCROMV"
   Ary = Split(Shts, "|")
   
   Set Dic = CreateObject("scripting.dictionary")
      For Cnt = LBound(Ary) To UBound(Ary) Step 2
         With Sheets(Ary(Cnt))
            If Cnt < 3 Then
               For Each Cl In .Range("F2", .Range("F" & Rows.Count).End(xlUp))
                  If LCase(Cl.Offset(, 6).Value) <> "reserves" Then
                     If Not Dic.exists(Cl.Value) Then Dic.Add Cl.Value, Nothing
                  End If
               Next Cl
            Else
               For Each Cl In .Range("F2", .Range("F" & Rows.Count).End(xlUp))
                  If Not Dic.exists(Cl.Value) Then Dic.Add Cl.Value, Nothing
               Next Cl
            End If
            Sheets(Ary(Cnt + 1)).Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(Dic.Count).Value = _
               Application.Transpose(Dic.keys)
            Dic.removeall
         End With
      Next Cnt

End Sub
 
Upvote 0
Re: Remove Duplicate Macro Help

Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,172
Members
449,071
Latest member
cdnMech

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