|
Private Sub CommandButton1_Click()
Dim arr, brr, crr, dic, dic1, i, j, m, a, tm, k, t
Dim str1, str2 As String
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Set dic = CreateObject("scripting.dictionary")
Set dic1 = CreateObject("scripting.dictionary")
'清空汇总表
With Sheets("汇总")
.Activate
.Rows("4:65536").Delete
.Columns("E:IV").Delete
End With
For i = 1 To 12
Range(Cells(2, 5 + (i - 1) * 3), Cells(2, 5 + (i - 1) * 3 + 2)).Merge
Cells(2, 5 + (i - 1) * 3).Value = "2022年" & i & "月"
dic1(i & "月") = 5 + (i - 1) * 3
Cells(3, 5 + (i - 1) * 3) = "出勤天数"
Cells(3, 5 + (i - 1) * 3 + 1) = "应发金额"
Cells(3, 5 + (i - 1) * 3 + 2) = "实发金额"
Next i
Cells.EntireColumn.AutoFit
For Each sht In Worksheets
If InStr(sht.Name, "月") Then
tm = Split(sht.Name, "月")(0)
If Val(tm) > a Then a = Val(tm)
arr = sht.Range("a1").CurrentRegion
For i = 4 To UBound(arr) - 1
str1 = Join(Array(arr(i, 2), arr(i, 3), arr(i, 4)), "|")
str2 = sht.Name & "|" & Join(Array(arr(i, 5), arr(i, 15), arr(i, 22)), "|")
' Debug.Print str1 & "-----" & str2
If Not dic.Exists(str1) Then
dic(str1) = str2
Else
dic(str1) = dic(str1) & "," & str2
End If
Next
End If
Next
arr = dic.keys
brr = dic.items
a = 4
For x = 0 To dic.Count - 1
Cells(a, 1) = x + 1
Cells(a, 2).Value = Split(arr(x), "|")(0)
Cells(a, 3).Value = Split(arr(x), "|")(1)
Cells(a, 4).Value = Split(arr(x), "|")(2)
crr = Split(brr(x), ",")
For j = 0 To UBound(crr)
k = dic1(Split(crr(j), "|")(0))
Cells(a, k).Value = Split(crr(j), "|")(1)
Cells(a, k + 1).Value = Split(crr(j), "|")(2)
Cells(a, k + 2).Value = Split(crr(j), "|")(3)
Next j
a = a + 1
Next
Set dic = Nothing
Set dic1 = Nothing
i = Range("A65536").End(xlUp).Row
Range("A" & i & ":D" & i).VerticalAlignment = xlCenter
Range("A" & i & ":D" & i).Merge
Range("A" & i).FormulaR1C1 = "合计"
Range("F" & i).FormulaR1C1 = "=SUM(R[-5]C:R[-1]C)"
Range("F" & i).AutoFill Destination:=Range("F" & i & ":G" & i), Type:=xlFillDefault
Range("E" & i & ":G" & i).AutoFill Destination:=Range("E" & i & ":AN" & i), Type:=xlFillDefault
Cells.EntireColumn.AutoFit
Range(Cells(2, 1), Cells(Range("A65536").End(xlUp).Row, Range("AV3").End(xlToLeft).Column)).Borders.LineStyle = 1
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
|
评分
-
1
查看全部评分
-
|