|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
请测试:- Sub Macro1()
- Dim p$, f$, d As Object, arr, brr(), crr(1 To 65530, 1 To 5), m&(), i&, j&, l&, t
- Application.ScreenUpdating = False
- Set d = CreateObject("scripting.dictionary")
- ReDim brr(1 To Sheets.Count)
- For i = 1 To Sheets.Count
- With Sheets(i)
- d(.Name) = i
- brr(i) = crr
- .UsedRange.Offset(1).ClearContents
- End With
- Next
- ReDim m(1 To Sheets.Count)
- p = ThisWorkbook.Path & ""
- f = Dir(p & "*.xls")
- Do While f <> ""
- If f <> ThisWorkbook.Name Then
- For l = 2 To Len(f) - 4
- t = d(Left(f, l))
- If t <> "" Then
- With GetObject(p & f)
- arr = .Sheets(1).[a1].CurrentRegion
- For i = 2 To .Sheets(1).[b65536].End(xlUp).Row
- m(t) = m(t) + 1
- brr(t)(m(t), 1) = m(t)
- For j = 2 To 5
- brr(t)(m(t), j) = arr(i, j)
- Next
- Next
- .Close False
- End With
- Exit For
- End If
- Next
- End If
- f = Dir
- Loop
- For i = 1 To Sheets.Count
- If m(i) Then Sheets(i).[a2].Resize(m(i), 5) = brr(i)
- Next
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|