|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
参与一下。。。- Sub ykcbf() '//2024.1.25
- Dim arr, brr(1 To 10000, 1 To 4)
- Set Fso = CreateObject("scripting.filesystemobject")
- Application.ScreenUpdating = False
- Set sh = ThisWorkbook.Sheets("Sheet1")
- st = sh.[c1].Value
- p = ThisWorkbook.Path & ""
- For Each f In Fso.GetFolder(p).Files
- If f.Name Like "*.xls*" Then
- If InStr(f.Name, ThisWorkbook.Name) = 0 Then
- fn = Fso.GetBaseName(f)
- Set wb = Workbooks.Open(f, 0)
- With wb.Sheets(1)
- r = .Cells(Rows.Count, 1).End(3).Row
- arr = .Range("a7:h" & r)
- c1 = Application.WorksheetFunction.Match("科目名称", .Rows(7), 0)
- c2 = Application.WorksheetFunction.Match("辅助核算", .Rows(7), 0)
- wb.Close False
- End With
- For i = 2 To UBound(arr)
- If CStr(arr(i, 1)) = CStr(st) Then
- m = m + 1
- brr(m, 1) = m
- brr(m, 2) = arr(i, c1)
- brr(m, 3) = arr(i, c2)
- brr(m, 4) = fn
- End If
- Next
- End If
- End If
- Next f
- On Error Resume Next
- With sh
- .UsedRange.Offset(2).Clear
- With .[a3].Resize(m, 4)
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|