|
Sub 合并()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
lj = ThisWorkbook.Path & "\"
With Sheets("质量表")
ar = .Range("a1:s10000")
For j = 1 To UBound(ar, 2)
If Trim(ar(1, j)) <> "" Then
d(Trim(ar(1, j))) = j
End If
Next j
f = Dir(lj & "*.xls*")
k = 1
Do While f <> ""
If f <> ThisWorkbook.Name Then
Set wb = Workbooks.Open(lj & f)
With wb.Worksheets(1)
r = .Cells(Rows.Count, 1).End(xlUp).Row
br = .Range("a1:x" & r)
End With
wb.Close False
For i = 2 To UBound(br)
If Trim(br(i, 1)) <> "" Then
t = d(br(i, 1))
If t = "" Then
k = k + 1
d(br(i, 1)) = k
t = k
ar(k, 1) = br(i, 1)
End If
For j = 1 To UBound(br, 2)
lh = d(Trim(br(1, j)))
If lh <> "" Then
ar(t, lh) = br(i, j)
End If
Next j
End If
Next i
End If
f = Dir
Loop
.[a1].Resize(k, UBound(ar, 2)) = ar
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|