|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 吉児 于 2019-7-31 14:36 编辑
帮忙修改一下第二个工作表的代码,效果需要跟第三个工作表显示的那样,万分感谢!
Sub 合计()
Dim i As Integer, j As Integer, arr, rng As Range, k As Integer, brr()
Dim l As Integer
Application.ScreenUpdating = False
For l = 1 To Range("a65536").End(xlUp).Row
If Cells(l, 1) = "" Then
Cells(l, 1).EntireRow.Delete
End If
Next
i = Sheets("data").Range("a65536").End(xlUp).Row
Sheets("data").Range("A1:f" & i).Sort Sheets("data").Range("A2"), 1
Sheets("data").Range("A1:f" & i).Select
Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(5), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
arr = Sheets("data").Range("a1:G" & Sheets("data").Range("b65536").End(xlUp).Row + 1)
Cells(Sheets("data").Range("a65536").End(xlUp).Row, 1).EntireRow.Delete
For j = 1 To UBound(arr)
If arr(j, 1) Like "*汇总" Then
arr(j, 1) = ""
arr(j - 1, 7) = arr(j, 5)
arr(j, 5) = ""
If rng Is Nothing Then
Set rng = Cells(j + 1, 1)
Else
Set rng = Union(rng, Cells(j + 1, 1))
End If
End If
Next
' Columns("a:a").Delete
ReDim brr(1 To UBound(arr))
c = 0
For k = 2 To UBound(arr)
If arr(k, 7) <> "" Then
brr(k) = c + arr(k, 7)
c = brr(k)
End If
Next
Sheets("data").Range("a1:g" & Sheets("data").Range("b65536").End(xlUp).Row + 1) = arr
Sheets("data").Range("h1").Resize(UBound(brr), 1) = Application.Transpose(brr)
Application.ScreenUpdating = True
End Sub
|
|