|
- Sub qs()
- Dim arr, i, dic
- Set dic = CreateObject("scripting.dictionary")
- arr = Sheet1.Range("c3").CurrentRegion.Value
- ReDim brr(1 To UBound(arr), 1 To UBound(arr, 2) + 1)
- ReDim crr(1 To 1, 1 To UBound(brr, 2)): crr(1, 1) = "合计"
- For i = 2 To UBound(arr)
- sm = 0
- If Not dic.exists(arr(i, 1)) Then
- m = m + 1
- brr(m, 1) = arr(i, 1)
- dic(arr(i, 1)) = m
- For c = 2 To 4
- brr(m, c) = arr(i, c)
- sm = sm + arr(i, c)
- Next
- brr(m, 5) = sm
- Else
- r = dic(arr(i, 1))
- For c = 2 To 4
- brr(r, c) = brr(r, c) + arr(i, c)
- sm = sm + brr(r, c)
- Next
- brr(r, 5) = sm
- End If
- Next
- For cl = 2 To UBound(brr, 2)
- crr(1, cl) = Application.WorksheetFunction.Sum(Application.Index(brr, 0, cl))
- Next
- Sheet1.Range("h3").Resize(m, 5) = brr
- Sheet1.Range("h3").Offset(m, 0).Resize(1, 5) = crr
- Set dic = Nothing
- End Sub
复制代码 |
|