|
こんにちは
こんな感じでいかがでしょうか。^d^
(Sheet1とSheet2から読み込み、Sheet3に書き出しています。
また、Item側(B列)には「,」(カンマ)が含まれていないことが条件です。)
Sub myDataBase()
Dim Dic As Object
Dim A As Variant
Dim i As Long
Dim K As Variant
Dim Itm As Variant
Set Dic = CreateObject("Scripting.Dictionary")
A = Worksheets("Sheet1").Range("A1").CurrentRegion.Value
For i = 1 To UBound(A)
Dic.Item(A(i, 1)) = A(i, 2)
Next
A = Worksheets("Sheet2").Range("A1").CurrentRegion.Value
For i = 1 To UBound(A)
Dic.Item(A(i, 1)) = Dic.Item(A(i, 1)) & "," & A(i, 2)
Next
ReDim A(1 To Dic.Count, 1 To 3)
i = 0
For Each K In Dic.Keys
i = i + 1
A(i, 1) = K
Itm = Split(Dic.Item(K), ",")
A(i, 2) = Itm(0)
A(i, 3) = Itm(1)
Next
Worksheets("Sheet3").Range("A1").Resize(Dic.Count, 3).Value = A
Set Dic = Nothing
End Sub
|
|