Code to copy duplicate values

asyamonique

Well-known Member
Joined
Jan 29, 2008
Messages
1,280
Office Version
  1. 2013
Platform
  1. Windows
Code:
Dim rngCell     As Range    Dim lngMyRow    As Long
    Dim wsSourceTab As Worksheet
    
    Application.ScreenUpdating = False
    
    Set wsSourceTab = Sheets("MasterList") 'Sheet name with data. Change to suit.


    With CreateObject("Scripting.Dictionary")
        For Each rngCell In wsSourceTab.Range("d2:d" & wsSourceTab.Range("d" & Rows.Count).End(xlUp).Row) 'Works down from cell A2. Change to suit.
            If Len(rngCell.Value) > 0 Then
                If Not .Exists(rngCell.Value) Then
                    .Add rngCell.Value, rngCell.Value
                    If lngMyRow = 0 Then
                        lngMyRow = 8 'Initial output row is 2. Change to suit.
                    Else
                        lngMyRow = lngMyRow + 1
                    End If
                    wsSourceTab.Range("d" & rngCell.Row).Copy Destination:=wsSourceTab.Range("a" & lngMyRow)
                End If
            End If
        Next rngCell
    End With

Good Day,
With above code how can I change the copy destination if I needed to copy the datas to another sheet?
Code:
Copy Destination:=wsSourceTab.Range("a" & lngMyRow)
Many thanks.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

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