|
- Sub 汇总()
- Dim vData As Variant, vRow As Variant, nCol As Integer
- Dim sName As String, vKey As Variant, oDic As Object, vFill As Variant, nFill As Long, nFillRow As Long, nOrder As Long
-
- Set oDic = CreateObject("Scripting.Dictionary")
- vData = Sheet1.[A1].CurrentRegion.Value
- ReDim vFill(1 To 5, 1 To UBound(vData))
- If UBound(vData) = 1 Then Exit Sub
-
- For vRow = 2 To UBound(vData)
- sName = Trim(vData(vRow, 1)) '姓名
- vKey = sName & "|" & Trim(vData(vRow, 5)) '课内容
- If Val(sName) > 0 Then sName = Replace(sName, Val(sName), "")
- If Not oDic.Exists(sName) Then
- nFill = nFill + 1
- oDic(sName) = nFill
- vFill(1, nFill) = sName
- End If
- nFillRow = oDic(sName)
- vFill(2, nFillRow) = vFill(2, nFillRow) + 1 '答次次数
- If Not oDic.Exists(vKey) Then
- oDic(vKey) = 0
- vFill(3, nFillRow) = vFill(3, nFillRow) + 1 '答次课数
- End If
- vFill(4, nFillRow) = vFill(4, nFillRow) + vData(vRow, 6) '总分
- Next
- If nFill > 0 Then
- ReDim Preserve vFill(1 To 5, 1 To nFill)
- vData = Application.WorksheetFunction.Transpose(vFill)
- vFill = Empty
- ReDim vFill(1 To nFill, 1 To 5)
- oDic.RemoveAll
- For vRow = 1 To nFill
- If oDic.Exists(vData(vRow, 4)) Then
- oDic(vData(vRow, 4)) = oDic(vData(vRow, 4)) & "|" & Trim(vRow)
- Else
- oDic(vData(vRow, 4)) = Trim(vRow)
- End If
- Next
- nFillRow = 0
- For nFill = 1 To oDic.Count
- vKey = Split(oDic(Application.WorksheetFunction.Large(oDic.keys, nFill)), "|")
- nOrder = nOrder + 1 '名次
- For Each vRow In vKey
- nFillRow = nFillRow + 1
- For nCol = 1 To 4
- vFill(nFillRow, nCol) = vData(Val(vRow), nCol)
- Next
- vFill(nFillRow, 5) = nOrder
- Next
- Next
- Sheet1.[J2:N2].Resize(nFillRow) = vFill
- End If
- End Sub
复制代码 |
|