|
Sub 汇总()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object, dc As Object
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
lj = ThisWorkbook.Path & "\"
With Sheets("Sheet1")
r = .Cells(Rows.Count, 1).End(xlUp).Row
y = .Cells(2, Columns.Count).End(xlToLeft).Column
If r >= 4 Then .Range(.Cells(4, 1), .Cells(r, y)) = Empty
ar = .Range(.Cells(1, 1), .Cells(1000, y))
For j = 2 To UBound(ar, 2) Step 4
If Trim(ar(1, j)) <> "" Then
zf = Left(Trim(ar(1, j)), 5)
d(zf) = j
End If
Next j
f = Dir(lj & "*.xls*")
k = 3
Do While f <> ""
If f <> ThisWorkbook.Name Then
Set wb = Workbooks.Open(lj & f, 0)
With wb.Worksheets(1)
rs = .Cells(Rows.Count, 1).End(xlUp).Row
br = .Range("a1:e" & rs)
End With
mc = Left(wb.Name, 5)
wb.Close False
lh = d(mc)
If lh <> "" Then
For i = 4 To UBound(br)
If Trim(br(i, 1)) <> "" Then
t = d(Trim(br(i, 1)))
If t = "" Then
k = k + 1
d(Trim(br(i, 1))) = k
t = k
ar(k, 1) = br(i, 1)
End If
For j = 2 To 5
ar(t, lh + j - 2) = br(i, j)
Next j
End If
Next i
End If
End If
f = Dir
Loop
.[a1].Resize(k, y) = ar
.[a1].Resize(k, y).Borders.LineStyle = 1
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|