|
本帖最后由 mjzxlmg 于 2012-6-21 08:04 编辑
[code=vb]Sub test()
Dim d As Object, arr, brr, i&, m&, s&, n&, ss&, d1 As Object
Set d = CreateObject("scripting.dictionary")
Set d1 = CreateObject("scripting.dictionary")
arr = Sheet1.[a1].CurrentRegion.Value
ReDim brr(1 To UBound(arr), 1 To 16384)
n = 1: m = 1
For i = 2 To UBound(arr) '第一行标题行,从第二行开始循环;如果没有标题行,把这句中的2改为1
ss = d1(arr(i, 1))
If ss = Empty Then
n = n + 1
d1(arr(i, 1)) = n
ss = n
brr(1, ss) = arr(i, 1)
End If
s = d(arr(i, 2))
If s = Empty Then
m = m + 1
d(arr(i, 2)) = m
s = m
brr(s, 1) = arr(i, 2)
End If
brr(s, ss) = arr(i, 3)
Next
brr(1, 1) = "Day"
With Sheet2
.UsedRange.ClearContents
.[a1].Resize(m, n).Value = brr
End With
Set d = Nothing: Set d1 = Nothing
End Sub[/code] |
|