Sub dcount()
Dim d As Object, arr, brr, i&, j&, k&
Set d = CreateObject("scripting.dictionary")
arr = Sheets("课程设置").[a1].CurrentRegion
For i = 3 To UBound(arr)
For j = 2 To UBound(arr, 2)
If arr(2, j) = "姓名" Then
t = arr(i, j)
If Not d.exists(t) Then Set d(t) = CreateObject("scripting.dictionary")
d(t)(arr(i, 1) & ",班") = d(t)(arr(i, 1) & ",班") & "," & arr(1, j)
d(t)(arr(i, 1) & ",节") = d(t)(arr(i, 1) & ",节") + Val(arr(i, j + 1))
End If
Next
Next
ActiveSheet.UsedRange.Offset(3) = ""
kr = d.keys
For i = 0 To UBound(kr)
t = kr(i): x = i + 4: ttl = 0: y = 0
Cells(x, 1) = i + 1
Cells(x, 2) = t
br = d(t).keys
For brx = 0 To UBound(br)
bj = br(brx)
If Right(bj, 2) = ",班" Then
y = y + 3
Cells(x, y) = Replace(bj, ",班", "")
Cells(x, y + 1) = Mid(d(t)(bj), 2)
Cells(x, y + 2) = d(t)(Cells(x, y).Value & ",节")
ttl = ttl + Cells(x, y + 2).Value
End If
Next
Cells(x, 18) = ttl
Next
MsgBox "ok"
Set d = Nothing
End Sub |