我真的很喜欢VBA中的字典对象。这不是本地可用的,但它非常有能力。您需要添加一个引用Microsoft Scripting Runtime
那么你可以做这样的事情:
Dim dic As Dictionary
Set dic = New Dictionary
Dim srcRng As Range
Dim lastRow As Integer
Dim ws As Worksheet
Set ws = Sheets("Sheet1")
lastRow = ws.Cells(1, 1).End(xlDown).Row
Set srcRng = ws.Range(ws.Cells(1, 1), ws.Cells(lastRow, 1))
Dim cell As Range
For Each cell In srcRng
If Not dic.Exists(cell.Value) Then
dic.Add cell.Value, cell.Value 'key, value
End If
Next cell
Set ws = Sheets("Sheet2")
Dim destRow As Integer
destRow = 1
Dim entry As Variant
'the Transpose function is essential otherwise the first key is repeated in the vertically oriented range
ws.Range(ws.Cells(destRow, 1), ws.Cells(dic.Count, 1)) = Application.Transpose(dic.Items)
我会去与选项4 1)录制宏2)复制柱A到第二页3)选择柱A,然后按删除数据选项卡下的复制按钮,如果你正在使用Excel 2007 4)对数据进行排序:)试一试,如果你被卡住了,然后回发:) –
+1对于Siddharth的答案。这应该很容易。 –
这样的问题在SO上被问过太多次了......看看以前的答案([例如](http://stackoverflow.com/a/5896692/119775)),尝试一下,看看它是否工作,回到我们有任何问题。 [This](http://meta.stackexchange.com/a/5235/164088)和[this](http://stackoverflow.com/questions/how-to-ask)也会对你有用。 –