Macro - Copy/Paste, Remove duplicates

psrs0810

Well-known Member
Joined
Apr 14, 2009
Messages
1,109
I need to setup a marco that will copy column C in ws "DeptXref" and paste it into ws "Table Build" column D with only the first four numbers and then remove duplicates.

Thanks
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Why do you want to copy the entire column "C" but then only paste in the first four rows into column "D"

Why not just copy the first four cells in column "C"
 
Upvote 0
I apologize if I miss stated.
in DeptXref column C, I have some departments with 4 digits and some with 5 digits. I need the first 4 digits for each cell which will create duplicates. From there, I need to remove those duplicates
 
Upvote 0
Hi
This assumes that your data starts in C1 & will paste into col D starting at D1
Code:
Sub Trim_removeDupes()

    Dim Cl As Range

    Sheets("DeptXref").Select
    With CreateObject("scripting.dictionary")
        For Each Cl In Range("C1", Range("C" & Rows.Count).End(xlUp))
            If Not .exists(Left(Cl.Value, 4)) Then .Add Left(Cl.Value, 4), Nothing
        Next Cl
        Sheets("Table Build").Range("D1:D" & .Count - 1) = Application.Transpose(.keys)
    End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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