
Originally Posted by
neowok
I MIGHT need to add some extra interest types as there are actually 14 (such as Tenant and Beneficiary which aren't in the sample sheet)
No need to do it....
Sub test()
Dim a, b, i As Long, dic As Object
Set dic = CreateObject("Scripting.Dictionary")
dic.CompareMode = 1
With Cells(1).CurrentRegion
a = .Value: ReDim b(1 To UBound(a, 1), 1 To 100)
b(1, 1) = a(1, 3)
With CreateObject("Scripting.Dictionary")
.CompareMode = 1
For i = 2 To UBound(a, 1)
If Not dic.exists(a(i, 2)) Then
dic(a(i, 2)) = dic.Count + 2
If UBound(b, 2) < dic.Count + 2 Then
ReDim Preserve b(1 To UBound(b, 1), 1 To UBound(b, 2) + 10)
End If
b(1, dic.Count + 1) = a(i, 2)
End If
If Not .exists(a(i, 3)) Then
.Item(a(i, 3)) = .Count + 2
b(.Count + 1, 1) = a(i, 3)
End If
b(.Item(a(i, 3)), dic(a(i, 2))) = b(.Item(a(i, 3)), dic(a(i, 2))) & _
IIf(b(.Item(a(i, 3)), dic(a(i, 2))) <> "", ", ", "") & a(i, 1)
Next
End With
With .Offset(, .Columns.Count + 2).Resize(i, dic.Count + 1)
.CurrentRegion.ClearContents: .Value = b
With .Offset(, 1).Resize(, .Columns.Count - 1)
.Sort .Rows(1), 1, Orientation:=xlLeftToRight
End With
.Columns.AutoFit
End With
End With
End Sub
Bookmarks