|
练习一下。
- Sub ykcbf() '//2024.12.16
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("Scripting.Dictionary")
- ReDim brr(1 To 10000, 1 To 100)
- On Error Resume Next
- For Each sht In Sheets
- If Val(sht.Name) Then
- n = n + 1
- With sht
- r = .Cells(Rows.Count, 1).End(3).Row
- r1 = .UsedRange.Find("员工姓名").Row
- c1 = .Rows(r1).Find("应发合计").Column
- c = .UsedRange.Columns.Count
- arr = .Cells(r1, 1).Resize(r - r1 + 1, c)
- End With
- For i = 2 To UBound(arr)
- s = arr(i, 1)
- If Not d.exists(s) Then
- m = m + 1
- d(s) = m
- brr(m, 1) = m
- brr(m, 2) = arr(i, 1)
- End If
- r = d(arr(i, 1))
- brr(r, 3) = brr(r, 3) + arr(i, c1)
- brr(r, 4) = brr(r, 4) + 1
- Next
- End If
- Next
- With Sheets("汇总分析")
- .UsedRange.Offset(1).Clear
- .Cells.Interior.ColorIndex = 0
- .[a1].Resize(1, 4).Interior.Color = 49407
- .Range("c:d").NumberFormatLocal = "0.00"
- With .[a2].Resize(m, 4)
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- For i = 1 To m
- .Cells(i + 1, 4).Value = brr(i, 3) / brr(i, 4)
- Next
- .[c2].Resize(m, 2).HorizontalAlignment = xlRight
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|