|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 汇总()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object, dc As Object
Dim br()
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
With Sheets("底表")
r = .Cells(Rows.Count, 1).End(xlUp).Row
y = .Cells(2, Columns.Count).End(xlToLeft).Column
If r < 6 Or y < 5 Then MsgBox "底表为空!": End
ar = .Range(.Cells(1, 1), .Cells(r, y))
End With
ReDim br(1 To UBound(ar), 1 To UBound(ar, 2))
br(1, 1) = "兼职": br(1, 2) = "合计"
k = 2: m = 2
For i = 6 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
If IsDate(ar(i, 1)) Then
t = d(Trim(ar(i, 1)))
If t = "" Then
k = k + 1
d(Trim(ar(i, 1))) = k
t = k
br(k, 1) = ar(i, 1)
End If
For j = 5 To y Step 4
If Trim(ar(2, j)) = "兼职" Then
If Trim(ar(i, j)) <> "" Then
lh = d(Trim(ar(i, j)))
If lh = "" Then
m = m + 1
d(Trim(ar(i, j))) = m
lh = m
br(1, m) = ar(i, j)
End If
br(t, lh) = br(t, lh) + ar(i, j + 3)
End If
End If
Next j
End If
End If
Next i
With Sheets("汇总表")
.UsedRange = Empty
.[a2].Resize(k, m) = br
For i = 3 To k + 1
.Cells(i, 2).FormulaR1C1 = "=SUM(RC[1]:RC[" & m - 2 & "])"
Next i
For j = 3 To m
.Cells(3, j).FormulaR1C1 = "=SUM(R[1]C:R[" & k - 2 & "]C)"
Next j
End With
MsgBox "ok!"
End Sub
|
|