I assume this is your input sheet? What would you want your output sheet to look like, as I don't understand from your words what you are wanting.
Option Explicit
Sub copy_uniques()
'Erik Van Geit
'070605
Dim rng As Range
Dim LR As Long 'Last Row
With Sheets(1)
LR = .Cells(Rows.Count, 3).End(xlUp).Row
Set rng = .Range(.Cells(1, 3), .Cells(LR, 3))
End With
Application.ScreenUpdating = False
With Sheets(2)
.Columns(1).ClearContents
rng.AdvancedFilter Action:=xlFilterCopy, CopyToRange:=.Cells(1, 1), unique:=True
End With
Application.ScreenUpdating = True
End Sub
A
1 Agent
2 LPG121
3 LPG14
4 LPG142
5 LPG173
6 LPG16
7 LPG6
8 LPGA4
ResultsSheet
[Table-It] version 09 by Erik Van Geit
Hi, try this
The list of agents on sheet 1 in column C (3) will go to sheet 2 column A.Code:Option Explicit Sub copy_uniques() 'Erik Van Geit '070605 Dim rng As Range Dim LR As Long 'Last Row With Sheets(1) LR = .Cells(Rows.Count, 3).End(xlUp).Row Set rng = .Range(.Cells(1, 3), .Cells(LR, 3)) End With Application.ScreenUpdating = False With Sheets(2) .Columns(1).ClearContents rng.AdvancedFilter Action:=xlFilterCopy, CopyToRange:=.Cells(1, 1), unique:=True End With Application.ScreenUpdating = True End Sub
Code:A 1 Agent 2 LPG121 3 LPG14 4 LPG142 5 LPG173 6 LPG16 7 LPG6 8 LPGA4 ResultsSheet [Table-It] version 09 by Erik Van Geit
Your example didn't contain duplicates as far as I can see!?
kind regards,
Erik
Option Explicit
Sub copy_uniques()
'Erik Van Geit (modified by jindon)
'070605
Sheets(2).Columns(1).Clear
With Sheets(1)
.Range("c1", .Range("c" & Rows.Count).End(xlUp)).Copy
Sheets(2).Cells(1).PasteSpecial xlPastValues
.Range("g2", .Range("g" & Rows.Count).End(xlUp)).Copy
Sheets(2).Cells(Rows.Count).End(xlUp)(2).PasteSpecial xlPastValues
End With
Sheets(2).Range("a1").CurrentRegion.Resize(, 1).AdvancedFilter _
Action:=xlFilterCopy, CopyToRange:=.Cells(1, 1), unique:=True
End Sub
I had no error: it worked for me.Run Time Error 9, subscript out of range