|
- Sub qs()
- Application.DisplayAlerts = False: Application.ScreenUpdating = False
- Dim arr, i, dic, sht As Worksheet
- Set dic = CreateObject("scripting.dictionary")
- ReDim brr(1 To 10000, 1 To 100)
- brr(1, 1) = "姓名"
- m = 2: c2 = 2: c3 = 3: c4 = 4
- For Each sht In Sheets
- If sht.Name <> "汇总" Then
- x = x + 1
- arr = sht.UsedRange.Value
- dic.RemoveAll
- For i = 3 To UBound(arr) - 1
- dic(arr(i, 2)) = Array(arr(i, 8), arr(i, 12), arr(i, 13))
- Next
-
- If x = 1 Then
- cl = 1
- brr(1, 2) = sht.Name
- brr(2, 2) = "单位": brr(2, 3) = "个人": brr(2, 4) = "合计"
- For Each k In dic.keys
- m = m + 1
-
- brr(m, 1) = k
- brr(m, 2) = dic(k)(0)
- brr(m, 3) = dic(k)(1)
- brr(m, 4) = dic(k)(2)
- Next
- Else
- c2 = c2 + 3: c3 = c3 + 3: c4 = c4 + 3
- brr(2, c2) = "单位": brr(2, c3) = "个人": brr(2, c4) = "合计"
- brr(1, c2) = sht.Name
- For i = 3 To m
- If dic.exists(brr(i, 1)) Then
- brr(i, c2) = dic(brr(i, 1))(0)
- brr(i, c3) = dic(brr(i, 1))(1)
- brr(i, c4) = dic(brr(i, 1))(2)
- dic.Remove brr(i, 1)
- End If
- Next
- If dic.Count > 0 Then '新来的员工
- For Each k2 In dic.keys
- m = m + 1
- brr(m, 1) = k2
- brr(m, c2) = dic(k2)(0)
- brr(m, c3) = dic(k2)(1)
- brr(m, c4) = dic(k2)(2)
- Next
- End If
- End If
- End If
- Next
- ReDim crr(1 To m, 1 To 3)
- crr(1, 1) = "合计": crr(2, 1) = "单位": crr(2, 2) = "个人": crr(2, 3) = "合计"
- For i = 3 To m
- For j = 2 To c2 Step 3
- crr(i, 1) = crr(i, 1) + brr(i, j)
- crr(i, 2) = crr(i, 2) + brr(i, j + 1)
- crr(i, 3) = crr(i, 3) + brr(i, j + 2)
- Next
- Next
- Set dic = Nothing
- With Sheet1
- .Range("a1:s10000").Clear
- .Range("a1").Resize(m, c4) = brr
- .Range("a1").Offset(, c4).Resize(m, 3) = crr
- .Range(.Cells(m + 1, 2), .Cells(m + 1, c4 + 3)).Formula = "=sum(b3:b" & m & ")"
- .Cells(m + 1, 1) = "合计"
- .Range("a1:a2").Merge
- For cc = 2 To 100 Step 3
- If Len(.Cells(1, cc)) > 0 Then
- .Cells(1, cc).Resize(1, 3).Merge
- End If
- Next
- With .Range("a1").CurrentRegion
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .Columns.AutoFit
- .Value = .Value
- End With
- End With
- Application.DisplayAlerts = True: Application.ScreenUpdating = True
- End Sub
复制代码 |
|