|
![](https://clubstatic.excelhome.net/image/common/ico_lz.png)
楼主 |
发表于 2024-9-29 14:59
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub ykcbf2() '//2024.9.29 汇总表自动生成
Application.ScreenUpdating = False
Set d = CreateObject("Scripting.Dictionary")
Set fso = CreateObject("Scripting.FileSystemObject")
p = ThisWorkbook.Path & ""
Set sh = ThisWorkbook.Sheets("汇总")
sh.Cells.Clear
ReDim brr(1 To 100000, 1 To 100)
m = 1: n = 0
For Each f In fso.GetFolder(p).Files
If LCase(f.Name) Like "*.xls*" Then
If InStr(f, "~$") = 0 Then
If InStr(f, ThisWorkbook.Name) = 0 Then
Set wb = Workbooks.Open(f, 0)
fn = fso.GetBaseName(f)
For Each sht In wb.Sheets
n = n + 1
With sht
r = .Cells(Rows.Count, 1).End(3).Row
c = .Cells(1, "XFD").End(1).Column
arr = .[a1].Resize(r, c)
Max = IIf(Max < c, c, Max)
If n = 1 Then
brr(1, 1) = "工作簿名"
brr(1, 2) = "工作表名"
For j = 1 To UBound(arr, 2)
brr(1, j + 2) = arr(1, j)
Next
End If
For i = 2 To UBound(arr)
m = m + 1
brr(m, 1) = fn
brr(m, 2) = .Name
brr(m, 3) = m
For j = 2 To UBound(arr, 2)
brr(m, j + 2) = arr(i, j)
Next
Next
End With
Next
wb.Close 0
End If
End If
End If
Next
With sh
.UsedRange.Clear
.[a1].Resize(1, Max + 2).Interior.Color = 49407
With .[a1].Resize(m, Max + 2)
.Value = brr
.Borders.LineStyle = 1
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
End With
Set d = Nothing
Application.ScreenUpdating = True
MsgBox "OK!"
End Sub
就是这个你上面发的汇总所有表的代码,大部分表格的标题在第2行,想把他改成第二行开始汇总所有。 |
|