Option Explicit
Sub test()
Dim arr, dic, i, j, t, n, s
Set dic = CreateObject("scripting.dictionary")
arr = [a1].CurrentRegion
ReDim brr(1 To Rows.Count, 1 To UBound(arr, 2))
For i = 2 To UBound(arr, 1)
If InStr(arr(i, 3), "+") Then
t = Split(arr(i, 3), "+")
For j = 0 To UBound(t)
If dic.exists(t(j)) Then
s = dic(t(j)): ReDim Preserve s(UBound(s) + 1)
s(UBound(s)) = arr(i, 4): dic(t(j)) = s
Else
dic(t(j)) = Array(arr(i, 4))
End If
Next
End If
Next
For i = 2 To UBound(arr, 1)
If dic.exists(arr(i, 3)) Then
t = dic(arr(i, 3))
For j = 0 To UBound(t)
n = n + 1: brr(n, 3) = arr(i, 3): brr(n, 4) = t(j)
Next
Else
n = n + 1
For j = 1 To UBound(arr, 2): brr(n, j) = arr(i, j): Next
End If
Next
With [l2]
.Resize(Rows.Count - 1, UBound(brr, 2)).ClearContents
.Resize(n, UBound(brr, 2)) = brr
.Offset(-1).Resize(, UBound(arr, 2)) = arr
End With
End Sub |