|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 沧海一粟123123 于 2024-11-21 13:20 编辑
Sub test()
Dim arr(1 To 10)
Dim mypath, filename As String
Dim k, x, y,m As Integer
Dim wb As Workbook
Dim arr1
mypath = ThisWorkbook.Path & "\明细\"
filename = Dir(mypath & "*.xls")
Do
k = k + 1
arr(k) = filename
filename = Dir
Loop Until filename = ""
For y = 1 To UBound(arr)
If Len(arr(y)) > 0 Then
Set wb = Workbooks.Open(mypath & arr(y))
For x = 1 To wb.Sheets.Count
i = ThisWorkbook.Sheets(1).Range("g65536").End(xlUp).Row + 1
m = wb.Sheets(x).Range("e15").End(xlDown).Row
wb.Sheets(x).Range("e16:s"&m).Copy ThisWorkbook.Sheets(1).Range("g" & i)
ThisWorkbook.Sheets(1).Range("e" & i) = Left(wb.Name, Len(wb.Name) - 4)
ThisWorkbook.Sheets(1).Range("f" & i) = wb.Sheets(x).Name
Next x
wb.Close True
End If
Next y
k = Range("g15").End(xlDown).Row
arr1 = Range("e16:f" & k)
For x = 1 To UBound(arr1) - 1
If arr1(x + 1, 1) = "" Then arr1(x + 1, 1) = arr1(x, 1)
If arr1(x + 1, 2) = "" Then arr1(x + 1, 2) = arr1(x, 2)
Next x
Range("e16:f" & k) = ""
Range("e16:f" & k) = arr1
End Sub
|
|