|
切换表的时候,对应要用到的参数都进行一次初始化处理- 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
- Dim wSH As Worksheet
-
- Set oDic = CreateObject("Scripting.Dictionary")
-
- For Each wSH In Sheets
- If wSH.Name = "本次统计" Or wSH.Name = "全期统计" Then
- vData = wSH.[A1].CurrentRegion.Value
- oDic.RemoveAll
- nFill = 0
- nOrder = 0
- 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 = Application.Substitute(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
- wSH.[J2:N2].Resize(nFillRow) = vFill
- End If
- End If
- Next
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|