|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
多表汇总- Sub ykcbf() '//2024.9.19 排重汇总
- 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 = 1
- bt = [{"单位","个人","合计"}]
- brr(1, 1) = "姓名"
- On Error Resume Next
- For Each sht In Sheets
- If sht.Name <> sh.Name Then
- n = n + 3
- With sht
- brr(1, n - 2) = .Name
- arr = .UsedRange
- For i = 3 To UBound(arr)
- If Val(arr(i, 1)) Then
- s = arr(i, 2)
- If Not d.exists(s) Then
- m = m + 1
- d(s) = m
- brr(m, 1) = s
- End If
- r = d(arr(i, 2))
- brr(r, n - 2) = brr(r, n - 2) + arr(i, 8)
- brr(r, n - 1) = brr(r, n - 1) + arr(i, 12)
- brr(r, n) = brr(r, n) + arr(i, 13)
- End If
- Next
- End With
- End If
- Next
- n = n + 3
- brr(1, n - 2) = "合计"
- m = m + 1
- brr(m, 1) = "合计"
- With sh
- .UsedRange.Clear
- .Cells.Interior.ColorIndex = 0
- .[a1].Resize(2, n).Interior.Color = 49407
- .[a3].Resize(m - 2, 1).Interior.Color = 5296274
- 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 = 2 To n Step 3
- .Cells(2, j).Resize(, 3) = bt
- .Cells(1, j).Resize(, 3).Merge
- Next
- For i = 3 To m - 1
- s1 = 0: s2 = 0: s3 = 0
- For j = 2 To n - 3
- s1 = s1 + IIf(.Cells(2, j).Value = .Cells(2, n - 2).Value, .Cells(i, j).Value, 0)
- s2 = s2 + IIf(.Cells(2, j).Value = .Cells(2, n - 1).Value, .Cells(i, j).Value, 0)
- s3 = s3 + IIf(.Cells(2, j).Value = .Cells(2, n).Value, .Cells(i, j).Value, 0)
- Next
- .Cells(i, n - 2).Value = s1
- .Cells(i, n - 1).Value = s2
- .Cells(i, n).Value = s3
- Next
- .[a1].Resize(2).Merge
- For j = 2 To n
- .Cells(m, j).Value = Application.Sum(.Cells(3, j).Resize(m - 3))
- Next
- End With
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|