|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 ykcbf1100 于 2024-6-21 08:46 编辑
数据表可以增减。- Sub ykcbf() '//2024.6.21 数据表可以增减。
- Application.ScreenUpdating = False
- Dim arr, brr, d
- Set d = CreateObject("Scripting.Dictionary")
- Set ws = ThisWorkbook
- Set sh = ws.Sheets("汇总")
- ReDim brr(1 To 1000, 1 To 100)
- m = 1: n = 2
- Count = ws.Sheets.Count
- brr(1, 1) = "序号": brr(1, 2) = "姓名": brr(1, Count + 2) = "年度合计"
- On Error Resume Next
- For x = 2 To Count
- With ws.Sheets(x)
- r = .UsedRange.Rows.Count
- Set Rng = .UsedRange.Find("打卡金额")
- r1 = Rng.Row: c1 = Rng.Column
- arr = .Range("a1:l" & r)
- fn = .Name
- End With
- For i = r1 + 1 To UBound(arr)
- s = Replace(arr(i, 3), " ", "")
- If Val(arr(i, 1)) Then
- If Not d.exists(s) Then
- m = m + 1
- d(s) = m
- brr(m, 1) = m - 1
- brr(m, 2) = s
- End If
- r = d(Replace(arr(i, 3), " ", ""))
- s = fn
- If Not d.exists(s) Then
- n = n + 1
- d(s) = n
- brr(1, n) = s
- End If
- c = d(fn)
- brr(r, c) = brr(r, c) + arr(i, c1)
- End If
- Next
- Next
- With sh
- bt = 3
- .UsedRange.Offset(2).Clear
- .Cells(bt, 1).Resize(m, Count + 2) = brr
- .Cells(bt, 3).Resize(1, Count - 1).Interior.Color = 49407
- .Cells(bt, 2).Resize(m, 1).Interior.Color = 5296274
- r = .Cells(Rows.Count, 1).End(3).Row
- .Cells(r + 1, 2) = "月份合计"
- With .Cells(bt, 1).Resize(m + 1, Count + 2)
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- For i = bt + 1 To r
- .Cells(i, Count + 2) = Application.Sum(.Cells(i, 3).Resize(, Count - 1))
- Next
- .Cells(bt, Count + 2).Resize(m + 1).Interior.ColorIndex = 8
- For j = 3 To Count + 2
- .Cells(r + 1, j) = Application.Sum(.Cells(bt + 1, j).Resize(m - 1))
- .Cells(r + 1, 2).Resize(, Count).Interior.ColorIndex = 15
- Next
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|