Copy the data of several columns to another sheet without duplicating

sofas

Well-known Member
Joined
Sep 11, 2022
Messages
559
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
Hello. I want to extract and copy data from several columns in Sheet1 without duplication and copy it to Sheet2 Starting from column 1 to column 10 ( A : J ) Starting from row 6
and copy it into Sheet 2 in row2 (R:Z)
I used this code, but it always repeats the first value while copying the lists. I want it to copy only the values.

VBA Code:
Sub test()
Application.ScreenUpdating = False
Sheet2.Range("R1:Z2000").ClearContents

Sheet1.Range("A6:A10000").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Sheet2.Range("R1"), Unique:=True
Sheet1.Range("B6:B10000").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Sheet2.Range("S1"), Unique:=True
Sheet1.Range("C6:C10000").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Sheet2.Range("T1"), Unique:=True
Sheet1.Range("D6:D10000").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Sheet2.Range("U1"), Unique:=True
Sheet1.Range("E6:E10000").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Sheet2.Range("V1"), Unique:=True
Sheet1.Range("F6:F10000").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Sheet2.Range("W1"), Unique:=True
Sheet1.Range("G6:G10000").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Sheet2.Range("X1"), Unique:=True
Sheet1.Range("H6:H10000").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Sheet2.Range("Y1"), Unique:=True
Sheet1.Range("I6:I10000").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Sheet2.Range("Z1"), Unique:=True
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hello. After searching, I found this code. It implements what is required, but it is very slow due to the large amount of data. Is there a better way?
With the ability to paste in row 5, for example, column 4



VBA Code:
Sub data_validation()  
Dim rSelection As Range
Dim ws As Worksheet
Dim vArray() As Long
Dim i As Long
Dim iColCount As Long
Application.ScreenUpdating = False
Set ws = sheet2
Set WS1 = Sheet1
    ws.Range("A1:J1000").ClearContents
   
  Set rSelection = WS1.Range("A6:J10000")
    iColCount = rSelection.Columns.Count
  For i = 1 To iColCount
        rSelection.Columns(i).Copy
    With ws.Cells(1, i)
      .PasteSpecial xlPasteValues
     ' .PasteSpecial xlPasteFormats
    End With
    ws.Columns(i).RemoveDuplicates Columns:=Array(1), Header:=xlGuess
   
    On Error Resume Next
      ws.UsedRange.SpecialCells(xlCellTypeBlanks).Delete Shift:=xlShiftUp
    On Error GoTo 0
        ws.Columns(i).AutoFit
  Next i
  ActiveWindow.ScrollColumn = 1
    Application.CutCopyMode = True
   
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,268
Messages
6,171,100
Members
452,379
Latest member
IainTru

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