|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test1()
- Dim ar, Dict As Object, i As Long, s As String
- Dim RowSize As Long, ColSize As Long, posCol As Long, posRow As Long
- Set Dict = CreateObject("Scripting.Dictionary")
- ar = Range("B2", Cells(Rows.Count, "H").End(xlUp))
- ReDim vResult(1 To UBound(ar), 1 To UBound(ar)) As String
- RowSize = 1
- vResult(RowSize, 1) = ar(1, UBound(ar, 2))
- For i = 2 To UBound(ar)
- s = ar(i, UBound(ar, 2))
- If Not Dict.Exists(s) Then
- RowSize = RowSize + 1
- vResult(RowSize, 1) = s
- vResult(RowSize, 2) = ar(i, 1)
- Dict(s) = Array(RowSize, 3)
- Else
- posRow = Dict(s)(0)
- posCol = Dict(s)(1)
- vResult(posRow, posCol) = ar(i, 1)
- Dict(s) = Array(posRow, posCol + 1)
- If posCol > ColSize Then ColSize = posCol
- End If
- Next
- With Range("M3")
- .CurrentRegion.ClearContents
- .Resize(RowSize, ColSize) = vResult
- End With
- Set Dict = Nothing
- Beep
- End Sub
复制代码 |
评分
-
2
查看全部评分
-
|