|
'再来一个
- Sub 分类汇总2()
- Dim arr As Variant, d As Object
- Dim i As Long, k As Long, j As Long
- Set d = CreateObject("scripting.dictionary")
- With Sheets("Sheet1")
- r = .Cells(Rows.Count, 5).End(xlUp).Row
- arr = .Range("e1:g" & r)
- End With
- k = 1
- For i = 2 To UBound(arr)
- If "" = d(arr(i, 1)) Then
- k = k + 1
- d(arr(i, 1)) = k
- arr(k, 1) = arr(i, 1)
- arr(k, 2) = arr(i, 2)
- arr(k, 3) = arr(i, 3)
- Else
- j = d(arr(i, 1))
- arr(j, 1) = arr(i, 1)
- arr(j, 2) = arr(j, 2) + arr(i, 2)
- arr(j, 3) = arr(j, 3) + arr(i, 3)
- End If
- hj_1 = hj_1 + arr(i, 2)
- hj_2 = hj_2 + arr(i, 3)
- Next i
- k = k + 1
- arr(k, 1) = "合计"
- arr(k, 2) = hj_1
- arr(k, 3) = hj_2
- With Sheets("Sheet2-结果")
- .[a1].CurrentRegion.Offset(1).Borders.LineStyle = 0
- .[a1].CurrentRegion.Offset(1) = Empty
- .[a1].Resize(k, UBound(arr, 2)) = arr
- .[a1].Resize(k, UBound(arr, 2)).Borders.LineStyle = 1
- End With
- 'MsgBox "ok!"
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|