|
Sub 统计()
Application.ScreenUpdating = False
Dim ar As Variant, br As Variant
Dim i As Long, r As Long, rs As Long
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("汇总表")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 4 Then MsgBox "请先录入水果名称!": End
.Range("b4:e" & r) = Empty
ar = .Range("a3:e" & r)
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
d(Trim(ar(i, 1))) = i
End If
Next i
f = Dir(ThisWorkbook.Path & "\数据文件\*.xls*")
Do While f <> ""
Set wb = Workbooks.Open(ThisWorkbook.Path & "\数据文件\" & f, 0)
With wb.Worksheets(1)
rs = .Cells(Rows.Count, 1).End(xlUp).Row
br = .Range("a3:e" & rs)
End With
wb.Close False
For i = 2 To UBound(br)
If Trim(br(i, 1)) <> "" Then
xh = d(Trim(br(i, 1)))
If xh <> "" Then
For j = 2 To UBound(br, 2)
ar(xh, j) = ar(xh, j) + br(i, j)
Next j
End If
End If
Next i
.Range("a3:e" & r) = ar
f = Dir
Loop
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|