|
Sub 导入数据()
Set d = CreateObject("scripting.dictionary")
tms = Timer
p = ThisWorkbook.Path & "\"
f = Dir(p & "*.xlsx")
Application.ScreenUpdating = False
ActiveSheet.UsedRange.Offset(1).ClearContents
brr = [a1].Resize(9999, 46)
For j = 1 To UBound(brr, 2)
If Len(brr(1, j)) > 0 Then d(Trim(brr(1, j))) = j
Next j
m = 1
Do While f <> ""
If f <> ThisWorkbook.Name Then
n = n + 1
Set wb = GetObject(p & f)
With wb.Sheets(1)
r = .Cells(.Rows.Count, 1).End(3).row
arr = .Range("a1:au" & r)
End With
wb.Close False
For i = 2 To UBound(arr)
m = m + 1
For j = 1 To UBound(arr, 2)
If d.exists(arr(1, j)) Then
c = d(arr(1, j))
brr(m, c) = arr(i, j)
End If
Next
Next
End If
f = Dir
Loop
Set wb = Nothing
With Sheet1
If m > 0 Then
.Range("d:d").NumberFormatLocal = "@"
.[a1].Resize(m, UBound(brr, 2)) = brr
End If
End With
Application.ScreenUpdating = True
MsgBox "汇总了:" & n & "个工作表;共有:" & m & "行数据 " & "用时:" & Format(Timer - tms, "0.00") & "秒"
End Sub
|
|