|
- Option Explicit
- Sub test2()
-
- Dim data, result() As String, dict As Object
- Dim i As Long, strKey As String
- Dim posRow As Long, posCol As Long, rowSize As Long, colSize As Long
-
- Set dict = CreateObject("Scripting.Dictionary")
- dict.CompareMode = 1 'TextCompare
- data = Range("A1").CurrentRegion
- ReDim result(1 To UBound(data), 1 To 99)
-
- rowSize = 1
- colSize = 1
- result(rowSize, colSize) = data(rowSize, 3)
-
- For i = 2 To UBound(data)
-
- strKey = data(i, 3)
- 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, 2)
- 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) & ";" & data(i, 1)
- Else
- result(posRow, posCol) = data(i, 1)
- End If
- Next
-
- With Range("F1")
- .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
复制代码 |
评分
-
1
查看全部评分
-
|