|
你试试行不?
Sub getData()
Dim d As Object, rMax%, arr
Dim i%, dtemp, dkey, data()
Set d = CreateObject("scripting.dictionary")
rMax = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
arr = Sheet1.Range("a2:b" & rMax)
Set d("ALL") = CreateObject("scripting.dictionary")
For i = 1 To UBound(arr)
If Not d.exists(arr(i, 1)) Then Set d(arr(i, 1)) = CreateObject("scripting.dictionary")
Set dtemp = d(arr(i, 1))
If Not dtemp.exists(arr(i, 2)) Then Set dtemp(arr(i, 2)) = CreateObject("scripting.dictionary")
Set dtemp = dtemp(arr(i, 2))
Set dtemp = d("ALL")
If Not dtemp.exists(arr(i, 1)) Then Set dtemp(arr(i, 1)) = CreateObject("scripting.dictionary")
Set dtemp = dtemp(arr(i, 1))
dtemp(arr(i, 1)) = dtemp(arr(i, 1)) + 1
Next
ReDim Preserve data(1 To d.Count - 1, 1 To 3)
For i = 1 To d.Count - 1
dkey = d.keys
data(i, 1) = dkey(i)
data(i, 2) = d(dkey(i)).Count
data(i, 3) = d("ALL")(dkey(i)).items()(0)
Next
Sheet1.[F2].Resize(UBound(data) - 1, UBound(data, 2)) = data
Set d = Nothing
End Sub |
|