|
代码供参考。。。- Sub ykcbf() '//2024.2.6
- Set Fso = CreateObject("scripting.filesystemobject")
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set ws = ThisWorkbook
- fns = [{"资产负债表","利润表"}]
- p = ws.Path & "\各公司财务报表"
- For x = 1 To 2
- Set sht = ws.Worksheets(fns(x))
- zrr = sht.UsedRange
- For Each f In Fso.GetFolder(p).Files
- If f.Name Like "*.xls" Then
- fn = Fso.GetBaseName(f)
- Set wb = Workbooks.Open(f, 0)
- With wb.Sheets(sht.Name)
- arr = .UsedRange
- wb.Close False
- End With
- If x = 1 Then
- For j = 1 To UBound(arr, 2) Step 4
- For i = 5 To UBound(arr)
- zrr(i, j + 2) = zrr(i, j + 2) + arr(i, j + 2)
- zrr(i, j + 3) = zrr(i, j + 3) + arr(i, j + 3)
- Next
- Next
- Else
- For i = 4 To UBound(arr)
- zrr(i, 3) = zrr(i, 3) + arr(i, 3)
- zrr(i, 4) = zrr(i, 4) + arr(i, 4)
- zrr(i, 5) = zrr(i, 5) + arr(i, 5)
- Next
- End If
- End If
- Next f
- sht.UsedRange = zrr
- Next
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|