|
发表于 2015-4-17 06:24
|
显示全部楼层
本楼为最佳答案
- Sub Macro1()
- Dim rng As Range, i&
- Sheet1.Activate
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- ActiveSheet.UsedRange.Clear
- [c1] = "合计1": [e1] = "合计2"
- With Sheets("数据源")
- .[a:b].Copy [a1]
- .[c:c].Copy [d1]
- End With
- Set rng = Cells(2, 1)
- For i = 3 To Range("a65536").End(xlUp).Row + 1
- If Cells(i, 1) = Cells(i - 1, 1) Then
- Set rng = Union(rng, Cells(i, 1))
- Else
- Cells(i - 1, 3) = Application.Sum(rng.Offset(0, 1))
- Cells(i - 1, 5) = Application.Sum(rng.Offset(0, 3))
- rng.Offset(0, 2).Merge
- rng.Offset(0, 4).Merge
- Set rng = Cells(i, 1)
- End If
- Next
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|