|
发表于 2010-6-4 09:05
|
显示全部楼层
本楼为最佳答案
Sub 汇总工作表() Dim d Dim Arr, ArrJG, i&, j&, PathName$, dirna, K, Temp Set d = CreateObject("Scripting.Dictionary") Application.ScreenUpdating = False '先处理本表 column1 = Range("IV1").End(xlToLeft).Column Arr = Range(Range("a2"), Cells(Range("A65536").End(xlUp).Row, column1)) K = 0 ReDim ArrJG(1 To column1, 1 To 1) For i = 1 To UBound(Arr) If Not d.exists(Arr(i, 1)) Then K = K + 1 ReDim Preserve ArrJG(1 To column1, 1 To K) d(Arr(i, 1)) = K End If Temp = d(Arr(i, 1)) For j = 1 To column1 ArrJG(j, Temp) = Arr(i, j) Next j Next i PathName = ThisWorkbook.Path & "\*.xls" dirna = Dir(PathName) Do While dirna <> "" If dirna <> "汇总表.xls" Then Set App = Application Set SourceBook = App.Workbooks.Open(ThisWorkbook.Path & "\" & dirna, 0, True) Set Sourcesheet = SourceBook.Worksheets("Sheet1") With Sourcesheet Arr = .Range(.Range("a2"), .Cells(.Range("A65536").End(xlUp).Row, column1)) End With SourceBook.Close False For i = 1 To UBound(Arr) If Not d.exists(Arr(i, 1)) Then K = K + 1 ReDim Preserve ArrJG(1 To column1, 1 To K) d(Arr(i, 1)) = K End If Temp = d(Arr(i, 1)) For j = 1 To column1 ArrJG(j, Temp) = Arr(i, j) Next j Next i Erase Arr End If dirna = Dir Loop Range(Range("A2"), Cells(65536, column1)).ClearContents Range("A2").Resize(UBound(ArrJG, 2), column1) = Application.Transpose(ArrJG) Application.ScreenUpdating = True End Sub
|
|