从两列中提取唯一的不同列表

所以我想通过省略重复的项目从两个单独的列创build一个组合列表。 我已经search并find一个公式,通过一次通过一列来结合列表这种方式。

第一种方式来结合

但我想结合这样的列:

第二种方式来结合

它首先通过每一行。

有没有一个公式或VBA代码呢? 谢谢。

编辑:这只是一种方式来显示我的请求。 添加颜色以显示组合列表如何sorting,这不是请求的一部分。 实际列表每个大约500行,由9个以上的数字ID号组成。

这将把你想要的顺序放在独特的单词。

 Sub foo() Dim rng As Range Dim ws As Worksheet Dim i&, j&, t& Dim dict As Object Dim iArr() As Variant Dim oarr() As Variant Dim itm As Variant Set dict = CreateObject("Scripting.Dictionary") Set ws = ActiveSheet With ws Set rng = .Range("A:B").Find("*", .Range("A1"), , , , xlPrevious) If Not rng Is Nothing Then iArr = .Range(.Cells(2, 1), .Cells(rng.Row, 2)).Value For i = LBound(iArr, 1) To UBound(iArr, 1) For j = LBound(iArr, 2) To UBound(iArr, 2) If iArr(i, j) <> "" Then On Error Resume Next dict.Add iArr(i, j), iArr(i, j) On Error GoTo 0 End If Next j Next i End If 'If your dataset is not that large <30,000, then you can use it directly with transpose .Range("C2").Resize(dict.Count) = Application.Transpose(dict.items) 'If your data is large then you will want to put it in a one dimensional array first 'just uncomment the below and comment the one line above ' ReDim oarr(1 To dict.Count, 1 To 1) ' t = 1 ' For Each itm In dict.keys ' oarr(t, 1) = dict(itm) ' t = t + 1 ' Next itm ' Range("C2").Resize(dict.Count) = oarr End With End Sub