|
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 = Sheet1.[a1].CurrentRegion
For i = 2 To UBound(ar)
d1(ar(i, 2)) = "": d2(ar(i, 1)) = ""
d3(ar(i, 1) & ar(i, 2)) = ar(i, 3)
Next
Sheet2.[b1].Resize(1, d1.Count) = d1.keys
Sheet2.[a2].Resize(d2.Count, 1) = WorksheetFunction.Transpose(d2.keys)
br = Sheet2.[a1].CurrentRegion
ReDim cr(1 To d2.Count, 1 To d1.Count)
For i = 2 To UBound(br)
For j = 2 To d1.Count + 1
cr(i - 1, j - 1) = d3(br(i, 1) & br(1, j))
Next
Next
Sheet2.[b2].Resize(1000, 50).ClearContents
Sheet2.[b2].Resize(UBound(cr), UBound(cr, 2)) = cr
MsgBox "ok"
End Sub
|
|