|
本帖最后由 一指禅62 于 2018-8-31 09:32 编辑
- Sub 汇总()
- Rem 警告:各表的字段顺序必须一致!!!!!
- Dim Sh As Worksheet, d As Object, arr, R&, i&
- Dim a(), n&, m&
- Set d = CreateObject("scripting.dictionary")
- Rem 提取薪酬统计表的既有数据(姓名)
- Set Sh = Sheets("薪酬统计")
- R = Sh.Range("C65536").End(3).Row
- If R > 4 Then
- arr = Sh.Range("A5:N" & R)
- For i = 1 To UBound(arr)
- If Not d.Exists(arr(i, 3)) Then
- n = n + 1: ReDim Preserve a(1 To 4, 1 To n)
- d(arr(i, 3)) = n
- End If
- Next
- End If
- For Each Sh In ThisWorkbook.Worksheets
- If Sh.Name <> "薪酬统计" Then
- R = Sh.Range("B65536").End(3).Row
- If R < 4 Then Exit Sub
- arr = Sh.Range("A4:X" & R)
- For i = 1 To UBound(arr)
- If Not d.Exists(arr(i, 2)) Then
- n = n + 1: ReDim Preserve a(1 To 4, 1 To n)
- d(arr(i, 2)) = n
- a(1, n) = arr(i, 13)
- a(2, n) = arr(i, 14)
- a(3, n) = arr(i, 19)
- a(4, n) = arr(i, 20)
- Else
- m = d.Item(arr(i, 2))
- a(1, m) = a(1, m) + arr(i, 13)
- a(2, m) = a(2, m) + arr(i, 14)
- a(3, m) = a(3, m) + arr(i, 19)
- a(4, m) = a(4, m) + arr(i, 20)
- End If
- Next
- End If
- Next
- If n = 0 Then Exit Sub
- With Sheets("薪酬统计")
- .Range("C5").Resize(n, 1) = WorksheetFunction.Transpose(d.keys)
- .Range("I5").Resize(n, 4) = WorksheetFunction.Transpose(a)
- End With
- End Sub
复制代码
|
|