|
本帖最后由 ykcbf1100 于 2024-5-20 14:20 编辑
新写一个,全表自动生成。
- Sub ykcbf() '//2024.5.20 各月汇总
- Set d = CreateObject("Scripting.Dictionary")
- Application.ScreenUpdating = False
- Set sh = ThisWorkbook.Sheets("汇总")
- ReDim brr(1 To 10000, 1 To 100)
- m = 2: n = 4
- bt1 = [{"序号","部门","姓名","身份证号码"}]
- bt2 = [{"出勤天数","应发金额","实发金额"}]
- For x = 1 To 4
- brr(1, x) = bt1(x)
- Next
- For Each sht In Sheets
- If Val(sht.Name) Then
- With sht
- r = .UsedRange.Find("合计").Row
- c = .UsedRange.Columns.Count
- c1 = Application.WorksheetFunction.Match(bt2(1), .Rows(3), 0)
- c2 = Application.WorksheetFunction.Match(bt2(2), .Rows(2), 0)
- c3 = Application.WorksheetFunction.Match(bt2(3), .Rows(2), 0)
- fn = .[a1].Value
- arr = .[a4].Resize(r - 4, c)
- For i = 1 To UBound(arr)
- s = CStr(arr(i, 4))
- If Not d.exists(s) Then
- m = m + 1
- d(s) = m
- brr(m, 1) = m
- For j = 2 To 4
- brr(m, j) = arr(i, j)
- Next
- End If
- r = d(CStr(arr(i, 4)))
- s = fn
- If Not d.exists(fn) Then
- n = n + 3
- d(fn) = n
- brr(1, n - 2) = fn
- brr(2, n - 2) = bt2(1)
- brr(2, n - 1) = bt2(2)
- brr(2, n) = bt2(3)
- End If
- c = d(fn)
- brr(r, c - 2) = arr(i, c1)
- brr(r, c - 1) = arr(i, c2)
- brr(r, c) = arr(i, c3)
- Next
- End With
- End If
- Next
- With sh
- .UsedRange.Clear
- .Columns(4).NumberFormatLocal = "@"
- With .[a1].Resize(m + 1, n)
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- .EntireColumn.AutoFit
- .Columns("D:D").ColumnWidth = 14
- .Columns("e:az").ColumnWidth = 11
- With .Font
- .Name = "微软雅黑"
- .Size = 11
- End With
- End With
- For j = 1 To 4
- .Cells(1, j).Resize(2).Merge
- Next
- For j = 5 To n Step 3
- .Cells(1, j).Resize(1, 3).Merge
- Next
- .[a1].Resize(1, n).Interior.Color = 49407
- .[e2].Resize(1, n - 4).Interior.Color = 5296274
- r = .Cells(Rows.Count, 1).End(3).Row
- .Cells(r + 1, 1) = "合计"
- .Cells(r + 1, 1).Resize(1, 4).Merge
- .Cells(r + 1, 5).Resize(1, n - 4).FormulaR1C1 = "=SUM(R3C:R" & "[-1]C)"
- End With
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|