|
|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub test()
Dim i, j As Integer
Dim ar, br, cr As Variant
Dim d1, d2, d3 As Object
Set d1 = CreateObject("scripting.dictionary")
Set d2 = CreateObject("scripting.dictionary")
Set d3 = CreateObject("scripting.dictionary")
ar = Sheets("工作表1").Range("a1:d" & Sheets("工作表1").[a65536].End(xlUp).Row)
For i = 3 To UBound(ar)
If ar(i, 2) <> "..." Then
d1(ar(i, 2)) = "": d2(ar(i, 3)) = ""
If Not d3.exists(ar(i, 2) & ar(i, 3)) Then
d3(ar(i, 2) & ar(i, 3)) = ar(i, 4)
Else
d3(ar(i, 2) & ar(i, 3)) = d3(ar(i, 2) & ar(i, 3)) & "," & ar(i, 4)
End If
End If
Next
With Sheets("工作表1")
.[g2].Resize(1 + d1.Count, 1 + d2.Count).ClearContents
.[g3].Resize(d1.Count, 1) = WorksheetFunction.Transpose(d1.keys)
.[h2].Resize(1, d2.Count) = d2.keys
br = .[g2].Resize(1 + d1.Count, 1 + d2.Count)
ReDim cr(1 To d1.Count, 1 To d2.Count)
For i = 2 To d1.Count + 1
For j = 2 To d2.Count + 1
cr(i - 1, j - 1) = d3(br(i, 1) & br(1, j))
Next
Next
.[h3].Resize(d1.Count, d2.Count) = cr
End With
MsgBox "ok"
End Sub |
|