|
- Sub ykcbf() '//2025.3.25 多表排重汇总
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("Scripting.Dictionary")
- Set Sh = ThisWorkbook.Sheets("工资汇总")
- ReDim brr(1 To 10000, 1 To 100)
- m = 2: n = 3
- bt = [{"手挡","時間","金額"}]
- On Error Resume Next
- For Each sht In Sheets
- If InStr("人员编号|工资汇总", sht.Name) = 0 Then
- arr = sht.UsedRange
- brr(1, 1) = arr(1, 2) & arr(1, 3): brr(1, 2) = arr(1, 4): brr(1, 3) = arr(1, 5)
- For x = 1 To 3
- brr(1, n + x) = sht.Name
- brr(2, n + x) = bt(x)
- brr(2, x) = arr(2, x + 2)
- Next
- n = n + 3
- For i = 4 To UBound(arr)
- s = arr(i, 3)
- If arr(i, 3) <> Empty Then
- If Not d.exists(s) Then
- m = m + 1
- d(s) = m
- brr(m, 1) = Format(arr(i, 3), "000000")
- brr(m, 2) = arr(i, 4)
- brr(m, 3) = arr(i, 5)
- End If
- r = d(arr(i, 3))
- brr(r, n - 2) = arr(i, 2)
- brr(r, n - 1) = arr(i, 102)
- brr(r, n) = arr(i, 103)
- End If
- Next
- End If
- Next
- For x = 1 To 3
- brr(1, n + x) = "合计"
- brr(2, n + x) = bt(x)
- Next
- n = n + 3
- With Sh
- .UsedRange.Clear
- .Cells.Interior.ColorIndex = 0
- .[a1].Resize(2, n).Interior.Color = 49407
- .[a3].Resize(m - 2, 1).Interior.Color = 5296274
- .Columns(1).NumberFormatLocal = "@"
- With .[a1].Resize(m, n)
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- With .Font
- .Name = "微软雅黑"
- .Size = 11
- End With
- End With
- For j = 4 To n Step 3
- .Cells(1, j).Resize(, 3).Merge
- Next
- For i = 3 To m
- For x = 1 To 3
- Sum = 0
- For j = 3 + x To n - 6 + x Step 3
- Sum = Sum + .Cells(i, j).Value * 1
- Next
- .Cells(i, n - 3 + x) = Sum
- Next
- Next
- Set Rng = .[a3].Resize(m - 2, n)
- Rng.Sort Rng.Columns(1), 1
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|