Scripting.Dictionaryオブジェクトを使用して、最初の2つの列の一意のリストを識別し、コメントIDのリストを収集します。
Option Explicit
Sub copyCommentIDs()
Dim a As Long, b As Long, aCOMs As Variant, k As Variant
Dim d As Long, dCOMs As Object
Set dCOMs = CreateObject("Scripting.Dictionary")
dCOMs.comparemode = vbTextCompare
With Worksheets("Sheet19")
'collect data from Old Sheet into an array
aCOMs = .Range(.Cells(3, "E"), .Cells(.Rows.Count, "G").End(xlUp)).Value2
End With
'build dictionary; collect comment IDs
For a = LBound(aCOMs, 1) To UBound(aCOMs, 1)
'if there a comment ID?
If CBool(Len(Trim(aCOMs(a, 3)))) Then
'concatenate/deliminate the first two columns
k = Join(Array(aCOMs(a, 1), aCOMs(a, 2)), ChrW(8203))
'does it exist in the dictionary?
If dCOMs.exists(k) Then
'it exists; concatenate the comment id onto the dict. key's item
dCOMs.Item(k) = Join(Array(dCOMs.Item(k), aCOMs(a, 3)), ", ")
Else
'does not exist; add a new dict key/item pair
dCOMs.Item(k) = aCOMs(a, 3)
End If
End If
Next a
With Worksheets("Sheet19")
'return the dictionay items to the new sheet
For b = 3 To .Cells(.Rows.Count, "A").End(xlUp).Row
'concatenate/deliminate the first two columns
k = Join(Array(.Cells(b, "A").Value2, .Cells(b, "B").Value2), ChrW(8203))
'does it exist in the dictionary?
If dCOMs.exists(k) Then
'transfer the comment id
.Cells(b, "C") = dCOMs.Item(k)
End If
Next b
End With
'clean up
Erase aCOMs
dCOMs.RemoveAll: Set dCOMs = Nothing
End Sub
なぜ簡単な数式? [INDEXとMATCHを使用したテーブル配列の2列の参照](http://stackoverflow.com/questions/33010190/two-column-lookup-in-table-array-using-index-and-match)を参照してください。 – Jeeped