|
Sub 汇总()
Application.ScreenUpdating = False
Dim ar As Variant
Dim i As Long, r As Long
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("流水")
.[a1].CurrentRegion.Offset(1) = Empty
ar = .Range("a1:x5000")
For j = 1 To UBound(ar, 2)
d(Trim(ar(1, j))) = j
Next j
f = Dir(ThisWorkbook.Path & "\*.xls*")
n = 1
Do While f <> ""
If f <> ThisWorkbook.Name Then
Set wb = Workbooks.Open(ThisWorkbook.Path & "\" & f, 0)
With wb.Worksheets(1)
r = .Cells(Rows.Count, 1).End(xlUp).Row
br = .Range("a4:x" & r)
End With
wb.Close False
For i = 2 To UBound(br)
If Trim(br(i, 1)) <> "" Then
n = n + 1
For j = 1 To UBound(br, 2)
lh = d(Trim(br(1, j)))
If lh <> "" Then
ar(n, lh) = br(i, j)
End If
Next j
End If
Next i
End If
f = Dir
Loop
.[a1].Resize(n, UBound(ar, 2)) = ar
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|