code copy data of certain column from sheet to another doesn't work

leap out

Active Member
Joined
Dec 4, 2020
Messages
271
Office Version
  1. 2016
  2. 2010
hello guys
I have this code it supposes data of column b in sheet1 to column e in sheet2 without any duplicated , but it doesn't happen any thing
so I appreciate if any body provide advice how can fix it .
VBA Code:
Sub CopyUnique()
    Dim s1 As Worksheet, FirstEmptyRow As Long, expCol As Long
    Set s1 = ActiveSheet
    With Sheets("sheet1")
        .Range("b:b").Name = "code1"
        expCol = .Range("code1").Column
        FirstEmptyRow = .Cells(.Rows.Count, expCol).End(xlUp).Row + 1
        s1.Range("e2:e100").Copy .Cells(FirstEmptyRow, expCol)
        .Range("code1").RemoveDuplicates Columns:=1, Header:=xlNo
    End With
End Sub
thanks
 
Ok, how about
VBA Code:
Sub CopyUnique()
   Dim s1 As Worksheet
   Set s1 = Sheets("Sheet2")
   With Sheets("sheet1")
      .Range("B2", .Range("B" & Rows.Count).End(xlUp)).Copy s1.Range("E" & Rows.Count).End(xlUp).Offset(1)
   End With
   s1.Range("E:E").RemoveDuplicates 1, xlNo
End Sub
 
Upvote 0
Solution

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,459
Messages
6,124,948
Members
449,198
Latest member
MhammadishaqKhan

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