|
Sub test1()
Dim data, result() As String, Dict As Object
Dim i As Long, strKey As String
Dim posRow As Long, rowSize As Long, posCol As Long, colSize As Long
Set Dict = CreateObject("Scripting.Dictionary")
data = Range("A1").CurrentRegion
ReDim result(1 To UBound(data), 1 To UBound(data))
rowSize = 1
colSize = 1
result(rowSize, colSize) = data(rowSize, colSize)
For i = 2 To UBound(data)
strKey = data(i, 1)
If Not Dict.Exists(strKey) Then
rowSize = rowSize + 1
result(rowSize, 1) = strKey
Dict.Add strKey, rowSize
End If
posRow = Dict(strKey)
strKey = data(i, 3)
If Not Dict.Exists(strKey) Then
colSize = colSize + 1
result(1, colSize) = strKey
Dict.Add strKey, colSize
End If
posCol = Dict(strKey)
If Len(result(posRow, posCol)) Then
result(posRow, posCol) = result(posRow, posCol) & vbCrLf & data(i, 2)
Else
result(posRow, posCol) = data(i, 2)
End If
Next
With Range("K1")
.CurrentRegion.Clear
With .Resize(rowSize, colSize)
.Borders.LineStyle = xlContinuous
.HorizontalAlignment = xlCenter
.Rows(1).Font.Bold = True
.Value = result
End With
End With
Set Dict = Nothing
Beep
End Sub
|
|