|
Option Explicit
Sub TEST6()
Dim ar, br, i&, j&, r&, iPosCol&, dic As Object, strPath$, strFileName$
Application.ScreenUpdating = False
Set dic = CreateObject("Scripting.Dictionary")
With [A1].CurrentRegion
.Offset(1).Clear
ar = .Resize(10 ^ 3).Value: r = 1
For j = 1 To UBound(ar, 2)
dic(ar(1, j)) = j
Next j
End With
strPath = ThisWorkbook.Path & "\"
strFileName = Dir(strPath & "*.xls")
Do Until strFileName = ""
If strFileName <> ThisWorkbook.Name Then
With GetObject(strPath & strFileName)
br = .Worksheets(1).[A1].CurrentRegion.Value
For i = 2 To UBound(br)
r = r + 1
For j = 1 To UBound(br, 2)
If dic.exists(br(1, j)) Then
iPosCol = dic(br(1, j))
ar(r, iPosCol) = br(i, j)
End If
Next j
Next i
.Close False
End With
End If
strFileName = Dir
Loop
With [A1].Resize(r, UBound(ar, 2))
.Value = ar
.HorizontalAlignment = xlCenter
.Borders.LineStyle = xlContinuous
End With
Set dic = Nothing
Application.ScreenUpdating = True
Beep
End Sub
|
|