|
|
Sub huizong()
Dim i, j As Integer
Dim ar, br, tepar As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
Dim p As String
p = ThisWorkbook.Path & "\"
Dim fso As Object
Set fso = CreateObject("scripting.filesystemobject")
Dim f
Dim wb As Workbook
ar = ThisWorkbook.Sheets("汇总").UsedRange
For i = 3 To UBound(ar)
d(ar(i, 1)) = i - 2
Next
ReDim br(1 To UBound(ar) - 2, 1 To 5)
For Each f In fso.getfolder(p).Files
If InStr(f.Name, "月") > 0 Then
Set wb = Workbooks.Open(f, 0)
tepar = wb.Sheets("工资").UsedRange
For i = 3 To UBound(tepar)
If tepar(i, 3) <> "" Then
If d.exists(tepar(i, 1)) Then
br(d(tepar(i, 1)), 1) = tepar(i, 3)
For j = 4 To UBound(tepar, 2)
br(d(tepar(i, 1)), j - 1) = tepar(i, j) + br(d(tepar(i, 1)), j - 1)
Next
End If
End If
Next
wb.Close False
End If
Next
ThisWorkbook.Sheets("汇总").[c3].Resize(100, 5).ClearContents
ThisWorkbook.Sheets("汇总").[c3].Resize(UBound(br), 5) = br
MsgBox "ok"
End Sub |
|