|
楼主 |
发表于 2024-1-26 09:41
|
显示全部楼层
本帖最后由 wcj6376tcp 于 2024-1-26 10:10 编辑
谢谢!就是需要这种效果,太厉害了!方便以后季报工资。在老师的基础上修改了一下。
Sub ykcbf() '//2024.1.25
Dim arr, brr, d
Dim Miny, Maxy, Rs As Long
Dim T As Date
T = Timer
Miny = InputBox("请输入要汇总的起始月份:", "输入起始月份数...", "1")
Maxy = InputBox("请输入要汇总的终止月份:", "输入终止月份数...", "12")
Range("K1").Value = Miny
Range("M1").Value = Maxy
Range("V1").Value = "=NOW()" '当前时间
Cells(1, 22) = Cells(1, 22).Value '记录汇总时间
'Application.ScreenUpdating = False
Set d = CreateObject("Scripting.Dictionary")
Set d1 = CreateObject("Scripting.Dictionary")
Set d2 = CreateObject("Scripting.Dictionary")
Set sh = ThisWorkbook.Sheets("汇总")
yf1 = Val(sh.[K1]): yf2 = Val(sh.[M1])
For Each sht In Sheets
If sht.Name <> sh.Name Then
fn = Val(sht.Name)
If fn >= yf1 And fn <= yf2 Then
With sht
r = .Cells(rows.Count, 1).End(3).Row
arr = .Range("A1:AA" & r)
For i = 4 To UBound(arr)
For j = 4 To UBound(arr, 2)
s = arr(i, 3) & "|" & arr(3, j)
d(s) = d(s) + arr(i, j)
s = arr(i, 3)
If Not d1.exists(s) Then
d1(s) = sht.Name
Else
d1(s) = IIf(InStr(d1(s), sht.Name), d1(s), d1(s) & " " & sht.Name)
End If
d2(arr(i, 3)) = ""
Next
Next
End With
End If
End If
Next
With sh
r = .Cells(rows.Count, 1).End(3).Row
.[A4:Z1000] = ""
.[A4].Resize(d2.Count, 1) = WorksheetFunction.Transpose(d2.keys)
arr = .Range("A1:Z" & r)
For i = 4 To UBound(arr)
For j = 2 To UBound(arr, 2) - 1
s = arr(i, 1) & "|" & arr(3, j)
If d.exists(s) Then
arr(i, j) = d(s)
End If
Next
s = arr(i, 1)
If d1.exists(s) Then
arr(i, UBound(arr, 2)) = d1(s)
Else
arr(i, UBound(arr, 2)) = ""
End If
Next
.Range("A1:Z" & r) = arr
End With
Set d = Nothing
'Application.ScreenUpdating = True
Rs = Sheets("汇总").Range("A3").CurrentRegion.rows.Count - 4 '获取行数
MsgBox "汇总" & Miny & "-" & Maxy & "月数据完毕!用时 " & Format((Timer - T), "0.0000") & " 秒," & vbCrLf & "共汇总 " & Rs & " 个人员数据。", vbInformation, ""
End Sub
|
|