VBA从第x行向下列出唯一值?

我有两个工作表。

工作表2:

Column CA A B B C D E E F G 

工作表1:

 Column G A B C D E F G 

根据以上所述,我试图在表格1中的列C中创build一个列G的唯一值列表。

这是我的代码到目前为止:

 Sub LIST() Dim Col As New Collection Dim itm Dim i As Long Dim CellVal As Variant Dim LastRow As Long '~~> Lets say looping through Row 1 to 22 For '~~> Range("A1:A22") as mentioned in your recent comment LastRow = ThisWorkbook.Worksheets("Data").Range("C" & Rows.Count).End(xlUp).Row 'Finds the last used row For i = 1 To LastRow CellVal = Sheets("Data").Range("C" & i).value On Error Resume Next Next i For Each itm In Columns(7) itm Next End Sub 

我是全新的vba,请somsone告诉我如何得到这个正常工作?

PS我需要这个列16行第16页上的列G中的值。

根据Darren的评论:

 Sub LIST() Dim r1 As Range, r2 As Range Set r1 = Sheets("Sheet1").Range("C:C") Set r2 = Sheets("Sheet2").Range("G1") r1.Copy r2 r2.RemoveDuplicates Columns:=1, Header:=xlNo End Sub 

如果你想在第一行下面开始,那么用"C7:C" & Rows.Countreplace"C:C"

另一种方式与词典

 Sub LIST() Dim dict As Dictionary Dim cell As Range Set dict = New Dictionary With Worksheets("Data") For Each cell In .Range("C1", .Cells(.Rows.Count, 1).End(xlUp) dict.Item(cell.Value) = 1 Next End With Worksheets("Sheet1").Range("G16").Value = Application,Transpose(dict.Keys) End Sub