|
代码如下。。。
Sub test()
Application.ScreenUpdating = False
Set fso = CreateObject("scripting.filesystemobject")
Set wb = ThisWorkbook
pth = wb.Path & "\"
Set sht = wb.Sheets("Sheet1")
r = sht.Cells(Rows.Count, 2).End(3).Row
arr = sht.Range("b6:b" & r)
Set d = CreateObject("scripting.dictionary")
For i = 1 To UBound(arr)
s = arr(i, 1)
If arr(i, 1) <> Empty Then
d(s) = i
End If
Next
ReDim crr(1 To UBound(arr), 1 To 4)
For Each ws In fso.getfolder(pth).Files
If fso.getbasename(wb.Name) <> fso.getbasename(ws) Then
If Left(ws.Name, 2) <> "~$" Then
With Workbooks.Open(ws, 0).Sheets("月汇总")
r = .Cells(.Rows.Count, 2).End(3).Row
brr = .Range("a6:l" & r - 1)
.Parent.Close 0
End With
For i = 1 To UBound(brr)
s = brr(i, 2)
If s <> Empty Then
If d.exists(s) Then
crr(d(s), 1) = crr(d(s), 1) + brr(i, 3)
crr(d(s), 2) = crr(d(s), 2) + brr(i, 4)
End If
End If
Next
End If
End If
Next
For i = 1 To UBound(crr) - 1
If crr(i, 1) <> Empty Or crr(i, 2) <> Empty Then
crr(i, 3) = "=sum(rc[-1]:rc3)"
crr(i, 4) = "=rc[-1]*50"
End If
Next
For j = 1 To 4
crr(UBound(crr), j) = "=sum(r[-1]c:r6c)"
Next
sht.[c6].Resize(UBound(crr), 4) = crr
Beep
Set d = Nothing
Application.ScreenUpdating = True
End Sub
|
评分
-
1
查看全部评分
-
|