|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 汇总()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object
Dim arr()
Set d = CreateObject("scripting.dictionary")
With Sheets("填写此表")
r = .Cells(Rows.Count, 1).End(xlUp).Row
y = .Cells(1, Columns.Count).End(xlToLeft).Column
If r < 7 Then MsgBox "填写此表为空!": End
ar = .Range(.Cells(1, 1), .Cells(r, y))
End With
ReDim arr(1 To UBound(ar), 1 To UBound(ar, 2))
k = 1: y = 1
arr(1, 1) = "月份"
For j = 4 To UBound(ar, 2) Step 2
If Trim(ar(1, j)) <> "" Then
t = d(Trim(ar(1, j)))
If t = "" Then
k = k + 1
d(Trim(ar(1, j))) = k
t = k
arr(k, 1) = ar(1, j)
End If
For i = 3 To UBound(ar)
If Trim(ar(i, j)) <> "" Then
lh = d(Trim(ar(i, j)))
If lh = "" Then
y = y + 1
d(Trim(ar(i, j))) = y
lh = y
arr(1, y) = ar(i, j)
End If
arr(t, lh) = arr(t, lh) + ar(i, j - 1)
End If
Next i
End If
Next j
y = y + 1
arr(1, 1) = "合计"
For i = 2 To k
hj = Application.Sum(Application.Index(arr, i, 0))
arr(i, y) = hj
Next i
With Sheets("汇总")
rs = .Cells(Rows.Count, 2).End(xlUp).Row
.Range("b3:e" & rs) = Empty
.[b3].Resize(k, y) = arr
End With
End Sub
|
|