|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub hz1()
- Dim nRow%, Arr(), Brr(), m%, n%, js$
- Dim ds As Object
- Application.DisplayAlerts = False
- Set ds = CreateObject("Scripting.Dictionary")
- With Sheets("sheet1")
- nRow = .Range("d65536").End(xlUp).Row
- Arr = .Range("a1:g" & nRow).Value
- End With
- ReDim Brr(1 To nRow, 1 To 5)
-
- For i = 2 To nRow
- js = CStr(Arr(i, 7) & Arr(i, 1))
- If Not ds.exists(js) Then
- n = n + 1
- ds(js) = n
- Brr(n, 1) = Arr(i, 7)
- Brr(n, 2) = Arr(i, 1)
- Brr(n, 3) = Arr(i, 4)
- Brr(n, 4) = Arr(i, 5)
- Brr(n, 5) = Arr(i, 6)
- Else
-
- Brr(ds(js), 3) = Brr(ds(js), 3) + Arr(i, 4)
- Brr(ds(js), 4) = Brr(ds(js), 4) + Arr(i, 5)
- Brr(ds(js), 5) = Brr(ds(js), 5) + Arr(i, 6)
-
- End If
- Next
-
- Brr(n + 1, 1) = "合计"
- [a3].Resize(n + 3, 5).Value = Brr
- Range("A3:E" & n + 1).Sort Key1:=Range("A3:A" & n + 1), Order1:=xlAscending
- For m = n + 2 To 2 Step -1
- If Cells(m, 1).Value = Cells(m - 1, 1).Value Then
- Union(Cells(m, 1), Cells(m - 1, 1)).Merge
- End If
- Next
-
- With Sheets("汇总")
- .Range("a3:e65536").Borders.LineStyle = 0
- .Range("a3:e" & n + 3).Borders.LineStyle = 1
- .Cells(n + 3, 3) = Application.WorksheetFunction.Sum(Range("C3:C" & n + 2))
- .Cells(n + 3, 4) = Application.WorksheetFunction.Sum(Range("D3:D" & n + 2))
- .Cells(n + 3, 5) = Application.WorksheetFunction.Sum(Range("E3:E" & n + 2))
- End With
- Application.DisplayAlerts = True
- End Sub
复制代码 按照你的代码改了一下,你看看这样可以不
|
评分
-
1
查看全部评分
-
|