|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub 多簿合并() 'fhxy
- Dim arr, brr(1 To 2000, 1 To 25)
- Dim n&, x&, y&, k&, myName$, myPath$
- Dim Sh As Worksheet, m%
- t = Timer
- Application.ScreenUpdating = False
- m = 0
- For Each Sh In Sheets
- If Sh.Name = "合并结果" Then MsgBox "合并结果存在!": m = m + 1
- Next
- If m = 0 Then
- ActiveSheet.Name = "合并结果"
- Cells.ClearContents
- With Application.FileDialog(msoFileDialogFolderPicker)
- If .Show = False Then Exit Sub
- myPath = .SelectedItems(1) & ""
- End With
- 'myPath = ThisWorkbook.Path & "" & "分表" & ""
- myName = Dir(myPath & "*.xls")
- Do While myName <> "" And myName <> "合并结果"
- With GetObject(myPath & myName)
- n = n + 1
- arr = .Sheets(1).Range("a1").CurrentRegion
- If n = 1 Then
- For x = 1 To UBound(arr)
- k = k + 1
- For y = 1 To UBound(arr, 2)
- brr(k, y) = arr(x, y)
- Next y
- Next x
- .Close False
- Else
- For x = 3 To UBound(arr)
- k = k + 1
- For y = 1 To UBound(arr, 2)
- brr(k, y) = arr(x, y)
- Next y
- Next x
- .Close False
- End If
- End With
- myName = Dir
- Loop
- Range("a1").Resize(UBound(brr), UBound(brr, 2)) = brr
- With Cells
- .EntireColumn.AutoFit
- .Font.Size = 9
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- If Application.CountA(Rows(2)) < 1 Then Rows(2).Delete
- End If
- Application.ScreenUpdating = True
- MsgBox Timer - t
- End Sub
复制代码 |
|