|
Sub 分类汇总()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object, dc As Object
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
With Sheets("sheet1")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 4 Then MsgBox "数据源为空!": End
ar = .Range("a1:d" & r)
Dim br()
y = 3: k = 1
ReDim br(1 To UBound(ar), 1 To 100)
br(1, 1) = "老师"
br(1, 2) = "负责班级"
br(1, 3) = "负责班数"
For i = 4 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
t = d(Trim(ar(i, 1)))
If t = "" Then
k = k + 1
d(Trim(ar(i, 1))) = k
t = k
br(k, 1) = ar(i, 1)
End If
lh = d(Trim(ar(i, 3)))
If lh = "" Then
y = y + 1
d(Trim(ar(i, 3))) = y
lh = y
br(1, y) = ar(i, 3)
End If
If br(t, 2) = "" Then
br(t, 2) = ar(i, 2)
Else
br(t, 2) = br(t, 2) & "|" & ar(i, 2)
End If
br(t, lh) = br(t, lh) + ar(i, 4)
End If
Next i
For i = 2 To k
dc.RemoveAll: m = 0: zd = ""
If InStr(br(i, 2), "|") = 0 Then
br(i, 3) = 1
Else
rr = Split(br(i, 2), "|")
For s = 0 To UBound(rr)
If Not dc.exists(rr(s)) Then
m = m + 1
If zd = "" Then
zd = rr(s)
Else
zd = zd & "/" & rr(s)
End If
dc(rr(s)) = ""
End If
Next s
br(i, 2) = zd
br(i, 3) = m
End If
Next i
.Range("g:z") = Empty
.[g3].Resize(k, y) = br
End With
Application.ScreenUpdating = True
End Sub
|
评分
-
1
查看全部评分
-
|